From patchwork Fri Sep 18 07:23:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ani Sinha X-Patchwork-Id: 1366595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=anisinha.ca Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=anisinha-ca.20150623.gappssmtp.com header.i=@anisinha-ca.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=kim5AhkQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bt524555Wz9sTM for ; Fri, 18 Sep 2020 17:24:44 +1000 (AEST) Received: from localhost ([::1]:53994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJAl8-0002zy-Ih for incoming@patchwork.ozlabs.org; Fri, 18 Sep 2020 03:24:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJAkS-0002v3-TI for qemu-devel@nongnu.org; Fri, 18 Sep 2020 03:24:00 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:41856) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJAkR-0003Im-4e for qemu-devel@nongnu.org; Fri, 18 Sep 2020 03:24:00 -0400 Received: by mail-pg1-x541.google.com with SMTP id y1so2947695pgk.8 for ; Fri, 18 Sep 2020 00:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anisinha-ca.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WIzwySGHusyyqcxBP6wP/5K/w/rrBhlYTKtBQXK9Uy8=; b=kim5AhkQjJJ0vfumEn51Fu3So+AFD2i+vdAhc6Me+WBEWr0MpOJVUS60fxbPFSfY7R E8asKDpWL3Q9J6wcJK0BcDFTC5gHmGPbhwqHzc3/JeHINAFi1taPcluLR15qPvC8hayN liiiU/RKeN6JCg7D7GE4srMRZI37j1yZvh7NPUjkrPpHKqqlE7YIiF96R7ywLoGQNpKA qJhpVweToi4n/xGyeMyfToa+7VpdK8OtEnGjD22x4F9JQgQzSMHrVnaqJbYHKHPfggZZ Af7jXsxthQxgFZwP+ABfOPMSXf7MLDoDnmjjS4JW80GTl0TfrAxbz+Iu5bWbLXA/6fyQ xxng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WIzwySGHusyyqcxBP6wP/5K/w/rrBhlYTKtBQXK9Uy8=; b=XcvxERKIb0Jrr+f210K2NtnMbm6s3a5jKuR0A1e5DAWIU5OlMHHrrnEGJQOy9Eb3/E 0+ZxdvkDJPcldreBzbwFeHb7yLobEonfue0F1LkG61MEBfbSakXsW7jC0EPo2gEgnHEq 9RObGvbhosE7MIR9rqS68wcwnJ2yFQknQ205wLh7WaB42qC1WluBrjGtBPIV9tRScAjc h0GZSgi9DyGY+R4evLysCyOjcqmttEnvRTUDnKYmWptjmKyitjZb+Yhg/JV+mmTNNH+k arwc4fxgdDwMeN1sSM89mQBozXIrxVEpXGDjJF6OwTQUJVM5h+Lt/PgWgq/nEXaaL3vB yKpg== X-Gm-Message-State: AOAM530s0NX6g9JfI5OtkKzLK2DrAojttvRVtkjtZW8NleNXedCp4KTU 7rk3pETlBVR6JlW1ViAS4EzI5g25YzmCqLvu X-Google-Smtp-Source: ABdhPJyuTStWl2CbrY675y6sCD2MhybD2MXyxvrk07GecwgcDqJM26OVq/VoIw2k9VDynBJ9KI1MlQ== X-Received: by 2002:a63:ba49:: with SMTP id l9mr26823283pgu.101.1600413837498; Fri, 18 Sep 2020 00:23:57 -0700 (PDT) Received: from localhost.localdomain ([115.96.124.157]) by smtp.googlemail.com with ESMTPSA id b18sm2010782pfr.4.2020.09.18.00.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 00:23:56 -0700 (PDT) From: Ani Sinha To: qemu-devel@nongnu.org Subject: [PATCH v9 04/13] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus Date: Fri, 18 Sep 2020 12:53:16 +0530 Message-Id: <20200918072325.9933-5-ani@anisinha.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918072325.9933-1-ani@anisinha.ca> References: <20200918072325.9933-1-ani@anisinha.ca> Received-SPF: none client-ip=2607:f8b0:4864:20::541; envelope-from=ani@anisinha.ca; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S. Tsirkin" , jusual@redhat.com, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Aleksandar Markovic , Paolo Bonzini , Ani Sinha , Igor Mammedov , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When ACPI hotplug for the root bus is disabled, the bsel property for that bus is not set. Please see the following commit: 3d7e78aa7777f ("Introduce a new flag for i440fx to disable PCI hotplug on the root bus"). As a result, when acpi_pcihp_find_hotplug_bus() is called with bsel set to 0, it may return the root bus. This can cause devices attached to the root bus to get hot-unplugged if the user issues the following set of commmands: outl 0xae10 0 outl 0xae08 your_slot Thanks to Julia for pointing this out here: https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html In this patch, we fix the issue in this function by checking if the bus which is returned by the function is actually hotpluggable. If not, we simply return NULL. This avoids the scenario where we were returning a non-hotpluggable bus. Signed-off-by: Ani Sinha Reviewed-by: Igor Mammedov --- hw/acpi/pcihp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 39b1f74442..32ae8b2c0a 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -147,6 +147,21 @@ static PCIBus *acpi_pcihp_find_hotplug_bus(AcpiPciHpState *s, int bsel) if (!bsel && !find.bus) { find.bus = s->root; } + + /* + * Check if find.bus is actually hotpluggable. If bsel is set to + * NULL for example on the root bus in order to make it + * non-hotpluggable, find.bus will match the root bus when bsel + * is 0. See acpi_pcihp_test_hotplug_bus() above. Since the + * bus is not hotpluggable however, we should not select the bus. + * Instead, we should set find.bus to NULL in that case. In the check + * below, we generalize this case for all buses, not just the root bus. + * The callers of this function check for a null return value and + * handle them appropriately. + */ + if (find.bus && !qbus_is_hotpluggable(BUS(find.bus))) { + find.bus = NULL; + } return find.bus; }