Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE206C3DA79 for ; Mon, 15 Jan 2024 08:58:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.667224.1038270 (Exim 4.92) (envelope-from ) id 1rPInE-00035V-C4; Mon, 15 Jan 2024 08:58:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 667224.1038270; Mon, 15 Jan 2024 08:58:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPInE-00035O-8M; Mon, 15 Jan 2024 08:58:04 +0000 Received: by outflank-mailman (input) for mailman id 667224; Mon, 15 Jan 2024 08:58:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPInD-00035I-TV for xen-devel@lists.xenproject.org; Mon, 15 Jan 2024 08:58:03 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3087d2ca-b384-11ee-98f1-6d05b1d4d9a1; Mon, 15 Jan 2024 09:58:02 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40e80046263so441845e9.2 for ; Mon, 15 Jan 2024 00:58:02 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id c11-20020a05600c0a4b00b0040d53588d94sm19151579wmq.46.2024.01.15.00.58.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 00:58:02 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3087d2ca-b384-11ee-98f1-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1705309082; x=1705913882; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Gg3E6MfcDuJwlFR9OvjQblrNS1r9dvoSxV9oblVARg8=; b=PD8ilqJv00o2LYYoPHETYHPVwxQpmOkmsSXUGSZJKIqNPEvOt3mEeU6NVh6CtUo6VI Q8AV3M+IpdKrloocJjIMEZyuExblOVFOwtPE5V0CBDG8APwcjH9mtpmK+M3+yU9wk0PN V/9ZkuvDVKJOJvNImJXMLXMCWUSldgnFzrqHz8FONUyRe2/qGVCd3zNQPYe/qsmL+7AC SL9cQ52Ic+DbL72gUkG2ZSQ7PeoH8J8B7GCpd+6DWfcAqksaI3OtJBdGxDL9Ohomnztp DILLFan+AjeXDoJIitb1LxKRt20psmV3ck8JNG8UyEhkqKM4W/FBU5Vri8d5Op7GHw46 LLKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705309082; x=1705913882; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Gg3E6MfcDuJwlFR9OvjQblrNS1r9dvoSxV9oblVARg8=; b=c4Ht2y54hpExjlnsM4qpydVJaxfv3akkFe62/OLMPH561/QwPuZ6o4yi+ZoWPMh1Qn myS9Cj80APzcOedUil7ZM020VOta5ZLk+F/6IujF4/MiKrTGwkVvKkjNwysl1lvzejv3 vw6LnvtPXABTLXo65bJ6hdlYWYZyoTQNihdoqR3/tOFiC4/rQkEnB7bizsHCnvRRHi4K GLyeysLykGXRRYQU8cPaBV3smF6tE+9tGiyeCClvtlj4HnTQfFWNvfgmBpZtaWXaq/HE 9FrugXB1Nm8l13lWFgsS9Ptxhf9+rFsKG/IwSMFd+qoaPMGGTV7AP/+vQBRx8/KRbmIq tvJw== X-Gm-Message-State: AOJu0YxVXaMQ6SDPZxtP9SQ+/QaNXB54AIVTNIVb53v1mBKzTD/CnP81 /A5zhHi/A+L2KZlLl7QaVWzGSzuiuUcx X-Google-Smtp-Source: AGHT+IEzutio8nveGpjeJIFQcWn4WHddqPTPbOu8Yl4TY5GnVDpDAMthsFEjakbX8fL3Bz/FLrc4Pw== X-Received: by 2002:a05:600c:5103:b0:40e:76b5:1463 with SMTP id o3-20020a05600c510300b0040e76b51463mr732241wms.29.1705309082264; Mon, 15 Jan 2024 00:58:02 -0800 (PST) Message-ID: <34b4cbf1-989d-43a0-aaea-717f06a79960@suse.com> Date: Mon, 15 Jan 2024 09:58:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12.1 01/15] vpci: use per-domain PCI lock to protect vpci structure Content-Language: en-US To: Stewart Hildebrand , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Cc: Oleksandr Andrushchenko , Andrew Cooper , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Jun Nakajima , Kevin Tian , Paul Durrant , Volodymyr Babchuk , xen-devel@lists.xenproject.org References: <20240109215145.430207-1-stewart.hildebrand@amd.com> <20240109215145.430207-2-stewart.hildebrand@amd.com> <590a157a-b9d4-4d2d-8aff-6584da3045c3@amd.com> <20240112181442.674031-1-stewart.hildebrand@amd.com> From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8U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T4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <20240112181442.674031-1-stewart.hildebrand@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 12.01.2024 19:14, Stewart Hildebrand wrote: > From: Oleksandr Andrushchenko > > Use the per-domain PCI read/write lock to protect the presence of the > pci device vpci field. This lock can be used (and in a few cases is used > right away) so that vpci removal can be performed while holding the lock > in write mode. Previously such removal could race with vpci_read for > example. > > When taking both d->pci_lock and pdev->vpci->lock, they should be > taken in this exact order: d->pci_lock then pdev->vpci->lock to avoid > possible deadlock situations. > > 1. Per-domain's pci_lock is used to protect pdev->vpci structure > from being removed. > > 2. Writing the command register and ROM BAR register may trigger > modify_bars to run, which in turn may access multiple pdevs while > checking for the existing BAR's overlap. The overlapping check, if > done under the read lock, requires vpci->lock to be acquired on both > devices being compared, which may produce a deadlock. It is not > possible to upgrade read lock to write lock in such a case. So, in > order to prevent the deadlock, use d->pci_lock in write mode instead. > > All other code, which doesn't lead to pdev->vpci destruction and does > not access multiple pdevs at the same time, can still use a > combination of the read lock and pdev->vpci->lock. > > 3. Drop const qualifier where the new rwlock is used and this is > appropriate. > > 4. Do not call process_pending_softirqs with any locks held. For that > unlock prior the call and re-acquire the locks after. After > re-acquiring the lock there is no need to check if pdev->vpci exists: > - in apply_map because of the context it is called (no race condition > possible) > - for MSI/MSI-X debug code because it is called at the end of > pdev->vpci access and no further access to pdev->vpci is made > > 5. Use d->pci_lock around for_each_pdev and pci_get_pdev_by_domain > while accessing pdevs in vpci code. > > Suggested-by: Roger Pau Monné > Suggested-by: Jan Beulich > Signed-off-by: Oleksandr Andrushchenko > Signed-off-by: Volodymyr Babchuk > Signed-off-by: Stewart Hildebrand > Reviewed-by: Roger Pau Monné While I know Roger did offer the tag with certain adjustments, ... > @@ -913,7 +911,12 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) > struct pci_dev *pdev = msix->pdev; > > spin_unlock(&msix->pdev->vpci->lock); > + read_unlock(&pdev->domain->pci_lock); > process_pending_softirqs(); > + > + if ( !read_trylock(&pdev->domain->pci_lock) ) > + return -EBUSY; > + > /* NB: we assume that pdev cannot go away for an alive domain. */ > if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) ) > return -EBUSY; ... I'm sure he was assuming you would get this right, in also dropping the 1st-try-acquired lock when this 2nd try-lock fails. Personally I feel this is the kind of change one would better not offer (or take) R-b ahead of time. I further think the respective comment in vpci_dump_msi() also wants adjusting from singular to plural. Jan