Commit d66af4df authored by Aaron Lu's avatar Aaron Lu Committed by Jeff Garzik

[libata] acpi: make ata_ap_acpi_handle not block

Since commit 30dcf76a, ata_ap_acpi_handle will always do a namespace
walk, which requires acquiring an acpi namespace mutex. This made it
impossible to be used when calling path has held a spinlock.

For example, it can occur in the following code path for pata_acpi:
ata_scsi_queuecmd (ap->lock is acquired)
  __ata_scsi_queuecmd
    ata_scsi_translate
      ata_qc_issue
        pacpi_qc_issue
          ata_acpi_stm
            ata_ap_acpi_handle
              acpi_get_child
                acpi_walk_namespace
                  acpi_ut_acquire_mutex (acquire mutex while holding lock)
This caused scheduling while atomic bug, as reported in bug #56781.

Actually, ata_ap_acpi_handle doesn't have to walk the namespace every
time it is called, it can simply return the bound acpi handle on the
corresponding SCSI host. The reason previously it is not done this way
is, ata_ap_acpi_handle is used in the binding function
ata_acpi_bind_host by ata_acpi_gtm when the handle is not bound to the
SCSI host yet. Since we already have the ATA port's handle in its
binding function, we can simply use it instead of calling
ata_ap_acpi_handle there. So introduce a new function __ata_acpi_gtm,
where it will receive an acpi handle param in addition to the ATA port
which is solely used for debug statement. With this change, we can make
ata_ap_acpi_handle simply return the bound handle for SCSI host instead
of walking the acpi namespace now.

Buglink: https://bugzilla.kernel.org/show_bug.cgi?id=56781
Reported-and-tested-by: <kenzopl@o2.pl>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent 3f1317a2
...@@ -60,7 +60,8 @@ acpi_handle ata_ap_acpi_handle(struct ata_port *ap) ...@@ -60,7 +60,8 @@ acpi_handle ata_ap_acpi_handle(struct ata_port *ap)
if (ap->flags & ATA_FLAG_ACPI_SATA) if (ap->flags & ATA_FLAG_ACPI_SATA)
return NULL; return NULL;
return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), ap->port_no); return ap->scsi_host ?
DEVICE_ACPI_HANDLE(&ap->scsi_host->shost_gendev) : NULL;
} }
EXPORT_SYMBOL(ata_ap_acpi_handle); EXPORT_SYMBOL(ata_ap_acpi_handle);
...@@ -239,28 +240,15 @@ void ata_acpi_dissociate(struct ata_host *host) ...@@ -239,28 +240,15 @@ void ata_acpi_dissociate(struct ata_host *host)
} }
} }
/** static int __ata_acpi_gtm(struct ata_port *ap, acpi_handle handle,
* ata_acpi_gtm - execute _GTM struct ata_acpi_gtm *gtm)
* @ap: target ATA port
* @gtm: out parameter for _GTM result
*
* Evaluate _GTM and store the result in @gtm.
*
* LOCKING:
* EH context.
*
* RETURNS:
* 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure.
*/
int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
{ {
struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER };
union acpi_object *out_obj; union acpi_object *out_obj;
acpi_status status; acpi_status status;
int rc = 0; int rc = 0;
status = acpi_evaluate_object(ata_ap_acpi_handle(ap), "_GTM", NULL, status = acpi_evaluate_object(handle, "_GTM", NULL, &output);
&output);
rc = -ENOENT; rc = -ENOENT;
if (status == AE_NOT_FOUND) if (status == AE_NOT_FOUND)
...@@ -294,6 +282,27 @@ int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm) ...@@ -294,6 +282,27 @@ int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
return rc; return rc;
} }
/**
* ata_acpi_gtm - execute _GTM
* @ap: target ATA port
* @gtm: out parameter for _GTM result
*
* Evaluate _GTM and store the result in @gtm.
*
* LOCKING:
* EH context.
*
* RETURNS:
* 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure.
*/
int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
{
if (ata_ap_acpi_handle(ap))
return __ata_acpi_gtm(ap, ata_ap_acpi_handle(ap), gtm);
else
return -EINVAL;
}
EXPORT_SYMBOL_GPL(ata_acpi_gtm); EXPORT_SYMBOL_GPL(ata_acpi_gtm);
/** /**
...@@ -1047,7 +1056,7 @@ static int ata_acpi_bind_host(struct ata_port *ap, acpi_handle *handle) ...@@ -1047,7 +1056,7 @@ static int ata_acpi_bind_host(struct ata_port *ap, acpi_handle *handle)
if (!*handle) if (!*handle)
return -ENODEV; return -ENODEV;
if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0) if (__ata_acpi_gtm(ap, *handle, &ap->__acpi_init_gtm) == 0)
ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment