From patchwork Tue Feb 1 16:25:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12732014 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 ABC74C433EF for ; Tue, 1 Feb 2022 16:25:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.263632.456427 (Exim 4.92) (envelope-from ) id 1nEvy0-0005NJ-Ah; Tue, 01 Feb 2022 16:25:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 263632.456427; Tue, 01 Feb 2022 16:25:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nEvy0-0005Lm-4v; Tue, 01 Feb 2022 16:25:16 +0000 Received: by outflank-mailman (input) for mailman id 263632; Tue, 01 Feb 2022 16:25:14 +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 1nEvxy-0005Ky-Ns for xen-devel@lists.xenproject.org; Tue, 01 Feb 2022 16:25:14 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8833c48b-837b-11ec-8eb8-a37418f5ba1a; Tue, 01 Feb 2022 17:25:13 +0100 (CET) Received: by mail-lf1-x134.google.com with SMTP id b9so34965825lfq.6 for ; Tue, 01 Feb 2022 08:25:13 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id z20sm2037887ljn.92.2022.02.01.08.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 08:25:12 -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: 8833c48b-837b-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fkt1iiffJfOyIvWsY76Bn/20kVLeJA6ML116mlUONbo=; b=E5ZvE1ExDici3mLfBGRByMNhSMDR1z1V0Jl1J1xe2WutHFL5N09fhAdb5VLIUW9HK+ P/lkLUCSA5p4M7u5kSwIuvzRYJV4wZYdiN9pr+Lkkxk/95xSt+agiquiiB5eAmbduPDe pv3jHuzZjqHlEVl122Sf6sJuAju4KN3omOsBmbNzSLS34f/KtYRhM98b95hrCgVRbkEp xWVMi9jjXf9RaWhY4vp9sYypkMBS1vT4aAqdr/6k5HgbrnZM7MiT6sfq/r4VOGbXqeRP kdmqeeQpeAyQUfoIHRQvjCbtRe67gmA1oE10VD36Ctt20olU2eCTxgUxDXRFjOhAIS12 vfnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fkt1iiffJfOyIvWsY76Bn/20kVLeJA6ML116mlUONbo=; b=2PUeynavqCW2sADe+r+GRKrj2jVCdQ09NT0uI9DKmG0BaTsqyDNJTkkJo8o7LWmnuK bNbk3l6+4pifIgBfR7bHHbbqkXVowvmx7FHiPH0eEO5+grCRRJKx0Tjpc0OcK6Smlu7F QpvqfkeaICHwDYVdLR+SID79qNYoe/gl2jb5d20Z+3ksXKl+jnBKq73MttkjiOawCsht p6Ud9OoA8P5n0B/FaSg7B+rB2jDqVVQF3de5U8A39K57Iw4cKJG9o/KuKvmS4QDTnyfu usc3ddbpcdsva/m2xlQtq8aHqL9Qjy/HEZHtP5Blv/psYYoa2IIqUGA/efVfO/7+6aU0 bEDQ== X-Gm-Message-State: AOAM5309QEcrmobCtVqFxJgZogNylz2J+uDBUtWGbYQS3XBdWd6+YhY0 CqNEv4F/IMlanwAA2O06xjzjCiC1OKk= X-Google-Smtp-Source: ABdhPJz7aQDwqw7IoCOwv24upNdvgpBXk6PPFLGQPG6c+KV0NT+moFC8V+wUyvqK76n3mynaOJyREg== X-Received: by 2002:a05:6512:a83:: with SMTP id m3mr19008711lfu.67.1643732712600; Tue, 01 Feb 2022 08:25:12 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH 1/4] rangeset: add RANGESETF_no_print flag Date: Tue, 1 Feb 2022 18:25:05 +0200 Message-Id: <20220201162508.417008-2-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201162508.417008-1-andr2000@gmail.com> References: <20220201162508.417008-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko There are range sets which should not be printed, so introduce a flag which allows marking those as such. Implement relevant logic to skip such entries while printing. While at it also simplify the definition of the flags by directly defining those without helpers. Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Jan Beulich --- Since v5: - comment indentation (Jan) Since v1: - update BUG_ON with new flag - simplify the definition of the flags --- xen/common/rangeset.c | 5 ++++- xen/include/xen/rangeset.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index 885b6b15c229..ea27d651723b 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -433,7 +433,7 @@ struct rangeset *rangeset_new( INIT_LIST_HEAD(&r->range_list); r->nr_ranges = -1; - BUG_ON(flags & ~RANGESETF_prettyprint_hex); + BUG_ON(flags & ~(RANGESETF_prettyprint_hex | RANGESETF_no_print)); r->flags = flags; safe_strcpy(r->name, name ?: "(no name)"); @@ -575,6 +575,9 @@ void rangeset_domain_printk( list_for_each_entry ( r, &d->rangesets, rangeset_list ) { + if ( r->flags & RANGESETF_no_print ) + continue; + printk(" "); rangeset_printk(r); printk("\n"); diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index 135f33f6066f..f7c69394d66a 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -49,8 +49,9 @@ void rangeset_limit( /* Flags for passing to rangeset_new(). */ /* Pretty-print range limits in hexadecimal. */ -#define _RANGESETF_prettyprint_hex 0 -#define RANGESETF_prettyprint_hex (1U << _RANGESETF_prettyprint_hex) +#define RANGESETF_prettyprint_hex (1U << 0) + /* Do not print entries marked with this flag. */ +#define RANGESETF_no_print (1U << 1) bool_t __must_check rangeset_is_empty( const struct rangeset *r); From patchwork Tue Feb 1 16:25:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12732016 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 5D7C1C4332F for ; Tue, 1 Feb 2022 16:25:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.263633.456433 (Exim 4.92) (envelope-from ) id 1nEvy0-0005Vb-Jt; Tue, 01 Feb 2022 16:25:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 263633.456433; Tue, 01 Feb 2022 16:25:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nEvy0-0005V4-G6; Tue, 01 Feb 2022 16:25:16 +0000 Received: by outflank-mailman (input) for mailman id 263633; Tue, 01 Feb 2022 16:25:15 +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 1nEvxz-0005Ky-Nh for xen-devel@lists.xenproject.org; Tue, 01 Feb 2022 16:25:15 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 895883a9-837b-11ec-8eb8-a37418f5ba1a; Tue, 01 Feb 2022 17:25:15 +0100 (CET) Received: by mail-lf1-x130.google.com with SMTP id x23so35118545lfc.0 for ; Tue, 01 Feb 2022 08:25:15 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id z20sm2037887ljn.92.2022.02.01.08.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 08:25:13 -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: 895883a9-837b-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zf0SXmh7ppwJ/thacBkxdMQhMGMB2nHh2LPFDThcNGk=; b=XpJvvbpEUYoLErsZRXX4lG9uNB57vhEPnHdXBzXza3jFxQkF3ceyXYdmRu/zzVxNo9 wS3WRaDKhYg42tjm37yfrqROI2/XNaY9mFYAeiQmlkQjWTNBYFlRm1bKj1IzsDEabg2Z ZXB+4Bu6dchfZJqi0iSgCrkEawgQXCAOWb1NbhfDM9dBa6NSLEO7oVnZ1oG6bIDrRDTp TKooKs1VjJxCRogreuWA4kxNK6j3cE98NOO3J5GgH7MgfyFo0b5/6jta7RYuKY6lfLuv 4lArSFjFF8BG2Ik5HQS9KDhGIEz20Atl8FyxnHj1x1Zu3TrYH6+x11pnvnAF0wgbE1WT iIgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zf0SXmh7ppwJ/thacBkxdMQhMGMB2nHh2LPFDThcNGk=; b=7lakmGsSd5T6hlySshD+HXDI7fOzAY4T7lYUazsOIqV2vXCkCrAICmm93nDJXNw4Mz GQ222DUcEcXCrZnmAh/JI3Egqxl8QKPVdpuAodqAdDxYkmWBrmo9scfwWcJQ7I6Ars/o 1/Tu7+xE5bA8BvV3igEuVKZPVn7BTcdflE7G97urEmfG2aWutC62udmWKDUQEs8hyeXZ 299WVN4VFPgQ4PYDuBvwt8wqmA7oGbKzSwrUFDyCdGBKatTC5wSNzaL1shAEfiehNR8O eUwXW10Bmw1D1y7jkRuoedi6d7sSjJG/ZR/kW5Qq5ErnZ0ZifCA6U0L2EGpgLbYka++y UmEw== X-Gm-Message-State: AOAM533h7JKhhY1vepMcGvpGVmblDkWpatOkkgZ7BmWgyGbbyGzbzCPb oG7Ll3SZFN4AUD/AuVng2M7eQdi1/bs= X-Google-Smtp-Source: ABdhPJyCvek8axmHS9oDXcyCrEQe3WzO0YHajhyUR+ohQ84kFaRbCqkLApNwjlY30/Vp5rNK+RSDQg== X-Received: by 2002:a05:6512:10d6:: with SMTP id k22mr20503490lfg.243.1643732713986; Tue, 01 Feb 2022 08:25:13 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH 2/4] rangeset: add rangeset_reset helper function Date: Tue, 1 Feb 2022 18:25:06 +0200 Message-Id: <20220201162508.417008-3-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201162508.417008-1-andr2000@gmail.com> References: <20220201162508.417008-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko This helper destroys all the ranges of the rangeset given. Please note, that it uses rangeset_remove_range which returns an error code on failure. This error code can be ignored as while destroying all the ranges no memory allocation is expected, so in this case it must not fail. To make sure this remains valid use BUG_ON if that changes in the future. Suggested-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko --- xen/common/rangeset.c | 6 ++++++ xen/include/xen/rangeset.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index ea27d651723b..9ca2b06cff22 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -525,6 +525,12 @@ void rangeset_swap(struct rangeset *a, struct rangeset *b) write_unlock(&b->lock); } +void rangeset_reset(struct rangeset *r) +{ + /* This doesn't allocate anything and must not fail. */ + BUG_ON(rangeset_remove_range(r, 0, ~0ULL)); +} + /***************************** * Pretty-printing functions */ diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index f7c69394d66a..e0d70d88bdd7 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -95,6 +95,9 @@ bool_t __must_check rangeset_contains_singleton( /* swap contents */ void rangeset_swap(struct rangeset *a, struct rangeset *b); +/* Destroy all ranges. */ +void rangeset_reset(struct rangeset *r); + /* Rangeset pretty printing. */ void rangeset_domain_printk( struct domain *d); From patchwork Tue Feb 1 16:25:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12732013 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 9339BC433F5 for ; Tue, 1 Feb 2022 16:25:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.263634.456455 (Exim 4.92) (envelope-from ) id 1nEvy3-00067j-1G; Tue, 01 Feb 2022 16:25:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 263634.456455; Tue, 01 Feb 2022 16:25:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nEvy2-00067a-TT; Tue, 01 Feb 2022 16:25:18 +0000 Received: by outflank-mailman (input) for mailman id 263634; Tue, 01 Feb 2022 16:25:17 +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 1nEvy0-0005Ky-WE for xen-devel@lists.xenproject.org; Tue, 01 Feb 2022 16:25:17 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8a11fe43-837b-11ec-8eb8-a37418f5ba1a; Tue, 01 Feb 2022 17:25:16 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id x23so35118682lfc.0 for ; Tue, 01 Feb 2022 08:25:16 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id z20sm2037887ljn.92.2022.02.01.08.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 08:25:15 -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: 8a11fe43-837b-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5iQETph6W13NDJUtDiBUfFdxzLSUx1dcP7y4KZ0Jn4=; b=Knowkl1OOo7PkZEnyXfB0uQdghQi1oSTzc8ntrp5jfpt8BnMjo+t1cybbx3gzhczJ4 rpQJgV4JPsFS3JSxQwcmmphJEUMBkm4Cx6TpvXhoojeZT+sI+WIO7sKQy9qSi/P5AxRg lTqJuLdBeNyBw0CRAGUvZieuUDHv5wIi6Vd2b1ZA89AdxnOSBM7ux5lTuyUCOHRxMp0o pQtl7ruyA+uUDJNKpkJ4VLl8snI54POPpIyvvBLQxGuL4dLSCMG1sJL9xdwbCbx8XQdy gerT5iPbHu5KxKDJRWETvL3F6KNtzdoe25xHTDeM5RyQ8zB7uUmQB2Jy7ocyrsIepEJY 0Lig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5iQETph6W13NDJUtDiBUfFdxzLSUx1dcP7y4KZ0Jn4=; b=03l+PPFZ++vRDbU3RIwTn2YiDAXQv2//BxI+gPMgWU490PfhlxCMWE9uoCA0MYBmHP P0QHX+lYnW9zxOFkiUCQdymcFbBF6hSS0hm4NDZbHpKw0XSnULtiC8S3S/2vmWqRTTFY Kb6uHFlZFLPAP77X8cWccMUVUTM/Tz5mY15txuqkO2+GUtCheYPDUCyDOH+YVDse6u0H x1PIG04QvFirMBwQyRyGXY1i8aDjoTpsIoXV3ACA/Glo0FvFkCpbCcJxGmqz3TZxkb44 tzigHOOyhtNSeZiJK/n6ylvCWE/F5LuE8JX0hicipnMGggFAwsrexcEhUZJDF3ShGh/I 6hjA== X-Gm-Message-State: AOAM530W8kYBK3ubw2Bfe+3UzawcneeewfQ3T/P0czaLRPgQGA4xP9YF G5qlKhrmiJ2KiHqo4ZBpno3nk69QEl8= X-Google-Smtp-Source: ABdhPJxALpiNGj4uqi5Ow3ML9Pg+P88S0Or/Bob/aFSPygbzA+vBkcO/PeE6dA6LrJe4HTVnHNR8Eg== X-Received: by 2002:a05:6512:1049:: with SMTP id c9mr16194147lfb.554.1643732715753; Tue, 01 Feb 2022 08:25:15 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH 3/4] vpci: shrink critical section in vpci_{read/write} Date: Tue, 1 Feb 2022 18:25:07 +0200 Message-Id: <20220201162508.417008-4-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201162508.417008-1-andr2000@gmail.com> References: <20220201162508.417008-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko Shrink critical section in vpci_{read/write} as racing calls to vpci_{read,write}_hw() shouldn't be a problem. Those are just wrappers around pci_conf_{read,write} functions, and the required locking (in case of using the IO ports) is already taken care in pci_conf_{read,write}. Please note, that we anyways split 64bit writes into two 32bit ones without taking the lock for the whole duration of the access, so it is possible to see a partially updated state as a result of a 64bit write: the PCI(e) specification don't seem to specify whether the ECAM is allowed to split memory transactions into multiple Configuration Requests and whether those could then interleave with requests from a different CPU. Signed-off-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko Acked-by: Roger Pau Monné Reviewed-by: Jan Beulich --- New in v6 --- xen/drivers/vpci/vpci.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 657697fe3406..fb0947179b79 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -370,6 +370,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) break; ASSERT(data_offset < size); } + spin_unlock(&pdev->vpci->lock); if ( data_offset < size ) { @@ -379,7 +380,6 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) data = merge_result(data, tmp_data, size - data_offset, data_offset); } - spin_unlock(&pdev->vpci->lock); return data & (0xffffffff >> (32 - 8 * size)); } @@ -475,13 +475,12 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, break; ASSERT(data_offset < size); } + spin_unlock(&pdev->vpci->lock); if ( data_offset < size ) /* Tailing gap, write the remaining. */ vpci_write_hw(sbdf, reg + data_offset, size - data_offset, data >> (data_offset * 8)); - - spin_unlock(&pdev->vpci->lock); } /* Helper function to check an access size and alignment on vpci space. */ From patchwork Tue Feb 1 16:25:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12732017 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 E3A1EC43219 for ; Tue, 1 Feb 2022 16:25:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.263635.456467 (Exim 4.92) (envelope-from ) id 1nEvy5-0006Qe-CE; Tue, 01 Feb 2022 16:25:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 263635.456467; Tue, 01 Feb 2022 16:25:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nEvy5-0006QQ-8b; Tue, 01 Feb 2022 16:25:21 +0000 Received: by outflank-mailman (input) for mailman id 263635; Tue, 01 Feb 2022 16:25:19 +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 1nEvy3-0005Ky-6T for xen-devel@lists.xenproject.org; Tue, 01 Feb 2022 16:25:19 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b204a2c-837b-11ec-8eb8-a37418f5ba1a; Tue, 01 Feb 2022 17:25:18 +0100 (CET) Received: by mail-lf1-x129.google.com with SMTP id z19so34876964lfq.13 for ; Tue, 01 Feb 2022 08:25:18 -0800 (PST) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id z20sm2037887ljn.92.2022.02.01.08.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 08:25:16 -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: 8b204a2c-837b-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OjkZoTR61B7utfXrmaTSlHnNCI9PmHivrLzjF3WsrhI=; b=YV1tZL4y3q4k8OZTWZxcehM3mB8NFp7Q3Cb8iwqbd7AtzGNfCHVOmBbNr838OjoBdG DBH18KUzRWRoE/iCN39IIX3Ez9YF3uLFVnb9cXQ/L4t+2zjdlGCfcW2xfo54nA6gDqyj 1uYmrndCRqmOxtNqNEbM/dPG7b/PFrJVj3i8aH7CKDl3+xT26Oce3tH8tRE2l60Y/MJr a4i40raUGshW+tycYqVZvjYweVMqhL4o9Y2zTvTAYU1RjtWU/lEyd/3KU8II/Gj8uKJ7 ePIXUN9xFPOWLBzCad4OwO/D86Bkj4q3ZMc/8NDhYyjruXc95IEOdmSw3Q6i1uLH7D5U qKFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OjkZoTR61B7utfXrmaTSlHnNCI9PmHivrLzjF3WsrhI=; b=2ZBNotwJ3yTjanq/5LpvjNRDu5mWtPx0PCxRlBkQQTnmfvdcMLPtQfeK/arWJaj7ZV M9Re557GsjS0j84IDcFZJ4K597Vcg7DdLNM2kuNsqahsuPv+EO559OkSUdM7lea0CIiC dc1s/Y+qA/L5HrJteJco5OBZG5XRdF5ELXwf64YADfQYaozefBhe+664BRIBYaCtxQ4Q NAWR9a8JADTeMkD42hlSlblFMqLt3fC1DPVhiKM1Lvs13zaporXN+kXerhfjHYgn44mL DPP4a3RCeztkZttdlnW6v7IplEAIkEkEGfIIeJYnSY+TCOVlJ3CggfPS8UA7Mw4HYZPJ Eg6g== X-Gm-Message-State: AOAM533IE2IIDQ19QtWFLQBuVXYVc6IeBGk4F61gWjVwL0V7coruWBBP Afd63Wd06L8RxPY9Z3Kvrnfa0ILuxJQ= X-Google-Smtp-Source: ABdhPJy4UCne6+TAN6DIconeVQuh4TMk8c/BIMlhpIaYC++3e55rF3rhZFj5G0/OtbhmUrakakPNaQ== X-Received: by 2002:a05:6512:32ca:: with SMTP id f10mr15292400lfg.329.1643732717478; Tue, 01 Feb 2022 08:25:17 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH 4/4] vpci: move lock outside of struct vpci Date: Tue, 1 Feb 2022 18:25:08 +0200 Message-Id: <20220201162508.417008-5-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201162508.417008-1-andr2000@gmail.com> References: <20220201162508.417008-1-andr2000@gmail.com> MIME-Version: 1.0 From: Roger Pau Monne This way the lock can be used to check whether vpci is present, and removal can be performed while holding the lock, in order to make sure there are no accesses to the contents of the vpci struct. Previously removal could race with vpci_read for example, since the lock was dropped prior to freeing pdev->vpci. Signed-off-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko --- Cc: Andrew Cooper Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini --- New in v5 of this series: this is an updated version of the patch published at https://lore.kernel.org/xen-devel/20180717094830.54806-2-roger.pau@citrix.com/ Changes since v5: - do not split code into vpci_remove_device_handlers_locked yet - move INIT_LIST_HEAD outside the locked region (Jan) - stripped out locking optimizations for vpci_{read|write} into a dedicated patch Changes since v2: - fixed pdev->vpci = xzalloc(struct vpci); under spin_lock (Jan) Changes since v1: - Assert that vpci_lock is locked in vpci_remove_device_locked. - Remove double newline. - Shrink critical section in vpci_{read/write}. --- tools/tests/vpci/emul.h | 5 ++- tools/tests/vpci/main.c | 4 +-- xen/arch/x86/hvm/vmsi.c | 8 ++--- xen/drivers/passthrough/pci.c | 1 + xen/drivers/vpci/header.c | 21 ++++++++---- xen/drivers/vpci/msi.c | 11 ++++-- xen/drivers/vpci/msix.c | 8 ++--- xen/drivers/vpci/vpci.c | 63 ++++++++++++++++++++++------------- xen/include/xen/pci.h | 1 + xen/include/xen/vpci.h | 3 +- 10 files changed, 78 insertions(+), 47 deletions(-) diff --git a/tools/tests/vpci/emul.h b/tools/tests/vpci/emul.h index 2e1d3057c9d8..d018fb5eef21 100644 --- a/tools/tests/vpci/emul.h +++ b/tools/tests/vpci/emul.h @@ -44,6 +44,7 @@ struct domain { }; struct pci_dev { + bool vpci_lock; struct vpci *vpci; }; @@ -53,10 +54,8 @@ struct vcpu }; extern const struct vcpu *current; -extern const struct pci_dev test_pdev; +extern struct pci_dev test_pdev; -typedef bool spinlock_t; -#define spin_lock_init(l) (*(l) = false) #define spin_lock(l) (*(l) = true) #define spin_unlock(l) (*(l) = false) diff --git a/tools/tests/vpci/main.c b/tools/tests/vpci/main.c index b9a0a6006bb9..26c95b08b6b1 100644 --- a/tools/tests/vpci/main.c +++ b/tools/tests/vpci/main.c @@ -23,7 +23,8 @@ static struct vpci vpci; const static struct domain d; -const struct pci_dev test_pdev = { +struct pci_dev test_pdev = { + .vpci_lock = false, .vpci = &vpci, }; @@ -158,7 +159,6 @@ main(int argc, char **argv) int rc; INIT_LIST_HEAD(&vpci.handlers); - spin_lock_init(&vpci.lock); VPCI_ADD_REG(vpci_read32, vpci_write32, 0, 4, r0); VPCI_READ_CHECK(0, 4, r0); diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 13e2a190b439..1f7a37f78264 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -910,14 +910,14 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) { struct pci_dev *pdev = msix->pdev; - spin_unlock(&msix->pdev->vpci->lock); + spin_unlock(&msix->pdev->vpci_lock); process_pending_softirqs(); /* NB: we assume that pdev cannot go away for an alive domain. */ - if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) ) + if ( !spin_trylock(&pdev->vpci_lock) ) return -EBUSY; - if ( pdev->vpci->msix != msix ) + if ( !pdev->vpci || pdev->vpci->msix != msix ) { - spin_unlock(&pdev->vpci->lock); + spin_unlock(&pdev->vpci_lock); return -EAGAIN; } } diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 1fad80362f0e..af648c6a19b5 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -328,6 +328,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) *((u8*) &pdev->bus) = bus; *((u8*) &pdev->devfn) = devfn; pdev->domain = NULL; + spin_lock_init(&pdev->vpci_lock); arch_pci_init_pdev(pdev); diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 40ff79c33f8f..bd23c0274d48 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -142,12 +142,13 @@ bool vpci_process_pending(struct vcpu *v) if ( rc == -ERESTART ) return true; - spin_lock(&v->vpci.pdev->vpci->lock); - /* Disable memory decoding unconditionally on failure. */ - modify_decoding(v->vpci.pdev, - rc ? v->vpci.cmd & ~PCI_COMMAND_MEMORY : v->vpci.cmd, - !rc && v->vpci.rom_only); - spin_unlock(&v->vpci.pdev->vpci->lock); + spin_lock(&v->vpci.pdev->vpci_lock); + if ( v->vpci.pdev->vpci ) + /* Disable memory decoding unconditionally on failure. */ + modify_decoding(v->vpci.pdev, + rc ? v->vpci.cmd & ~PCI_COMMAND_MEMORY : v->vpci.cmd, + !rc && v->vpci.rom_only); + spin_unlock(&v->vpci.pdev->vpci_lock); rangeset_destroy(v->vpci.mem); v->vpci.mem = NULL; @@ -285,6 +286,12 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) continue; } + spin_lock(&tmp->vpci_lock); + if ( !tmp->vpci ) + { + spin_unlock(&tmp->vpci_lock); + continue; + } for ( i = 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) { const struct vpci_bar *bar = &tmp->vpci->header.bars[i]; @@ -303,12 +310,14 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) rc = rangeset_remove_range(mem, start, end); if ( rc ) { + spin_unlock(&tmp->vpci_lock); printk(XENLOG_G_WARNING "Failed to remove [%lx, %lx]: %d\n", start, end, rc); rangeset_destroy(mem); return rc; } } + spin_unlock(&tmp->vpci_lock); } ASSERT(dev); diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 5757a7aed20f..e3ce46869dad 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -270,7 +270,7 @@ void vpci_dump_msi(void) rcu_read_lock(&domlist_read_lock); for_each_domain ( d ) { - const struct pci_dev *pdev; + struct pci_dev *pdev; if ( !has_vpci(d) ) continue; @@ -282,8 +282,13 @@ void vpci_dump_msi(void) const struct vpci_msi *msi; const struct vpci_msix *msix; - if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) ) + if ( !spin_trylock(&pdev->vpci_lock) ) continue; + if ( !pdev->vpci ) + { + spin_unlock(&pdev->vpci_lock); + continue; + } msi = pdev->vpci->msi; if ( msi && msi->enabled ) @@ -323,7 +328,7 @@ void vpci_dump_msi(void) } } - spin_unlock(&pdev->vpci->lock); + spin_unlock(&pdev->vpci_lock); process_pending_softirqs(); } } diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index 846f1b8d7038..5310cc3ff520 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -225,7 +225,7 @@ static int msix_read(struct vcpu *v, unsigned long addr, unsigned int len, return X86EMUL_OKAY; } - spin_lock(&msix->pdev->vpci->lock); + spin_lock(&msix->pdev->vpci_lock); entry = get_entry(msix, addr); offset = addr & (PCI_MSIX_ENTRY_SIZE - 1); @@ -254,7 +254,7 @@ static int msix_read(struct vcpu *v, unsigned long addr, unsigned int len, ASSERT_UNREACHABLE(); break; } - spin_unlock(&msix->pdev->vpci->lock); + spin_unlock(&msix->pdev->vpci_lock); return X86EMUL_OKAY; } @@ -297,7 +297,7 @@ static int msix_write(struct vcpu *v, unsigned long addr, unsigned int len, return X86EMUL_OKAY; } - spin_lock(&msix->pdev->vpci->lock); + spin_lock(&msix->pdev->vpci_lock); entry = get_entry(msix, addr); offset = addr & (PCI_MSIX_ENTRY_SIZE - 1); @@ -370,7 +370,7 @@ static int msix_write(struct vcpu *v, unsigned long addr, unsigned int len, ASSERT_UNREACHABLE(); break; } - spin_unlock(&msix->pdev->vpci->lock); + spin_unlock(&msix->pdev->vpci_lock); return X86EMUL_OKAY; } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index fb0947179b79..c015a4d77540 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -35,12 +35,10 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) -void vpci_remove_device(struct pci_dev *pdev) +static void vpci_remove_device_locked(struct pci_dev *pdev) { - if ( !has_vpci(pdev->domain) ) - return; + ASSERT(spin_is_locked(&pdev->vpci_lock)); - spin_lock(&pdev->vpci->lock); while ( !list_empty(&pdev->vpci->handlers) ) { struct vpci_register *r = list_first_entry(&pdev->vpci->handlers, @@ -50,15 +48,26 @@ void vpci_remove_device(struct pci_dev *pdev) list_del(&r->node); xfree(r); } - spin_unlock(&pdev->vpci->lock); xfree(pdev->vpci->msix); xfree(pdev->vpci->msi); xfree(pdev->vpci); pdev->vpci = NULL; } +void vpci_remove_device(struct pci_dev *pdev) +{ + if ( !has_vpci(pdev->domain) ) + return; + + spin_lock(&pdev->vpci_lock); + if ( pdev->vpci ) + vpci_remove_device_locked(pdev); + spin_unlock(&pdev->vpci_lock); +} + int vpci_add_handlers(struct pci_dev *pdev) { + struct vpci *vpci; unsigned int i; int rc = 0; @@ -68,12 +77,14 @@ int vpci_add_handlers(struct pci_dev *pdev) /* We should not get here twice for the same device. */ ASSERT(!pdev->vpci); - pdev->vpci = xzalloc(struct vpci); - if ( !pdev->vpci ) + vpci = xzalloc(struct vpci); + if ( !vpci ) return -ENOMEM; - INIT_LIST_HEAD(&pdev->vpci->handlers); - spin_lock_init(&pdev->vpci->lock); + INIT_LIST_HEAD(&vpci->handlers); + + spin_lock(&pdev->vpci_lock); + pdev->vpci = vpci; for ( i = 0; i < NUM_VPCI_INIT; i++ ) { @@ -83,7 +94,8 @@ int vpci_add_handlers(struct pci_dev *pdev) } if ( rc ) - vpci_remove_device(pdev); + vpci_remove_device_locked(pdev); + spin_unlock(&pdev->vpci_lock); return rc; } @@ -152,8 +164,6 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, r->offset = offset; r->private = data; - spin_lock(&vpci->lock); - /* The list of handlers must be kept sorted at all times. */ list_for_each ( prev, &vpci->handlers ) { @@ -165,14 +175,12 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, break; if ( cmp == 0 ) { - spin_unlock(&vpci->lock); xfree(r); return -EEXIST; } } list_add_tail(&r->node, prev); - spin_unlock(&vpci->lock); return 0; } @@ -183,7 +191,6 @@ int vpci_remove_register(struct vpci *vpci, unsigned int offset, const struct vpci_register r = { .offset = offset, .size = size }; struct vpci_register *rm; - spin_lock(&vpci->lock); list_for_each_entry ( rm, &vpci->handlers, node ) { int cmp = vpci_register_cmp(&r, rm); @@ -195,14 +202,12 @@ int vpci_remove_register(struct vpci *vpci, unsigned int offset, if ( !cmp && rm->offset == offset && rm->size == size ) { list_del(&rm->node); - spin_unlock(&vpci->lock); xfree(rm); return 0; } if ( cmp <= 0 ) break; } - spin_unlock(&vpci->lock); return -ENOENT; } @@ -311,7 +316,7 @@ static uint32_t merge_result(uint32_t data, uint32_t new, unsigned int size, uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) { const struct domain *d = current->domain; - const struct pci_dev *pdev; + struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; uint32_t data = ~(uint32_t)0; @@ -327,7 +332,12 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) if ( !pdev ) return vpci_read_hw(sbdf, reg, size); - spin_lock(&pdev->vpci->lock); + spin_lock(&pdev->vpci_lock); + if ( !pdev->vpci ) + { + spin_unlock(&pdev->vpci_lock); + return vpci_read_hw(sbdf, reg, size); + } /* Read from the hardware or the emulated register handlers. */ list_for_each_entry ( r, &pdev->vpci->handlers, node ) @@ -370,7 +380,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) break; ASSERT(data_offset < size); } - spin_unlock(&pdev->vpci->lock); + spin_unlock(&pdev->vpci_lock); if ( data_offset < size ) { @@ -414,7 +424,7 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data) { const struct domain *d = current->domain; - const struct pci_dev *pdev; + struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; const unsigned long *ro_map = pci_get_ro_map(sbdf.seg); @@ -440,7 +450,14 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, return; } - spin_lock(&pdev->vpci->lock); + spin_lock(&pdev->vpci_lock); + if ( !pdev->vpci ) + { + spin_unlock(&pdev->vpci_lock); + vpci_write_hw(sbdf, reg, size, data); + return; + } + /* Write the value to the hardware or emulated registers. */ list_for_each_entry ( r, &pdev->vpci->handlers, node ) @@ -475,7 +492,7 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, break; ASSERT(data_offset < size); } - spin_unlock(&pdev->vpci->lock); + spin_unlock(&pdev->vpci_lock); if ( data_offset < size ) /* Tailing gap, write the remaining. */ diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index b6d7e454f814..3f60d6c6c6dd 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -134,6 +134,7 @@ struct pci_dev { u64 vf_rlen[6]; /* Data for vPCI. */ + spinlock_t vpci_lock; struct vpci *vpci; }; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 3f32de9d7eb3..d06efc3cea46 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -31,7 +31,7 @@ int __must_check vpci_add_handlers(struct pci_dev *dev); /* Remove all handlers and free vpci related structures. */ void vpci_remove_device(struct pci_dev *pdev); -/* Add/remove a register handler. */ +/* Add/remove a register handler. Must be called holding the vpci_lock. */ int __must_check vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, vpci_write_t *write_handler, @@ -60,7 +60,6 @@ bool __must_check vpci_process_pending(struct vcpu *v); struct vpci { /* List of vPCI handlers for a device. */ struct list_head handlers; - spinlock_t lock; #ifdef __XEN__ /* Hide the rest of the vpci struct from the user-space test harness. */