From patchwork Wed Mar 31 10:32:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBE75C433E1 for ; Wed, 31 Mar 2021 10:36:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4E9CB61582 for ; Wed, 31 Mar 2021 10:36:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E9CB61582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103830.198019 (Exim 4.92) (envelope-from ) id 1lRYCT-0004aB-J0; Wed, 31 Mar 2021 10:35:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103830.198019; Wed, 31 Mar 2021 10:35:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCT-0004a4-FC; Wed, 31 Mar 2021 10:35:49 +0000 Received: by outflank-mailman (input) for mailman id 103830; Wed, 31 Mar 2021 10:35:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCS-0004Zp-Fk for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:35:48 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2418dee0-b4d0-4766-a8d0-54044651bb31; Wed, 31 Mar 2021 10:35:46 +0000 (UTC) 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: 2418dee0-b4d0-4766-a8d0-54044651bb31 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186946; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=pf+3mEgT/PwOonbrF+sYgx8kqAd51PG7gUiL4p8/xD4=; b=ZLOLXRnifKA7JPdELVN2dF38absTHnxAzzELNl8eMzbG7k84LZPxM37r t4tWzJpaG2tNR1qOt8JSyf3ZOO8u04RdFZ6uWE2tJFUoSHmMDUWK+AWpb cUmbGlkevg1nJ+UGtW0tot9Pbt3xH0zwVlHNTIWKaU9B6Y856XyC+mcuj U=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: FoHfbWWLulHxf0Oq02Rw5muDVV+bOEFRDshmpU6vAEFD9RPgUsW3okBrFLBCxJd2a+RAxD/SjN BciA09C4zjPkgLML03ZlmDTs/3puAx2bgexSiwzYh7gLVZ8J5S/9fQQEWNqE2l9GzK0xBX6tnq Qd5H/JFA6YwRm401DQcp43YB+4wBGP8UkF0/S3hTj2x2CO3l3PzLzq1R5cPEmcNt2IBO2KiBps A8KIw5yW6hat/nfl2NFa2JwWIngtTXxQHgAVh81ZgMmkY19OiQvQVzugSAfYlby91mOwjsMVuM Dkc= X-SBRS: 5.2 X-MesageID: 40917024 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:NUQrAKkXsmP9nFPxnJ80pOPqYIrpDfOpj2dD5ilNYBxZY6Wkvu iUtrAyyQL0hDENWHsphNCHP+26TWnB8INuiLN/AZ6LZyOjnGezNolt4c/ZwzPmEzDj7eI178 tdWoBEIpnLAVB+5PyW3CCRD8sgzN6b8KqhmOfZyDNXQRt3brx7hj0ZNi+wOCRNNW17LLA+E4 eR4dcCmiGpfm4ZYt/+Kn4OWeXCoNOjruObXTctARk75A6SyQ658bKSKWnk4j4ycRNqhY0j/2 /MjhDj6syY3c2T5xfA2wbonvJrsfT7zN8rPr3vtuE0LXHWhh+sdMBdXdS5zUsIicWOzHpvr9 XWuRcnOK1ImgPsV0W4uwHk1QWl8BtG0Q6a9XaijXHuodP0SVsBYqIr7+IpEWqq12MasN5xy6 5N1W6C3qAndy/opyjh+8POEyhji0vcmwtSrccok3ddXYECAYUhyrA3wUU9KuZkIAvKrKojEO VoEfjG4udXfV6wfxnizxdS6e3pcXIpEhicRE8e/uSTzjhNhXh8i3AV3coFgx47hd4AYqgBw9 6BHrVjlblIQMNTRaVhBN0ZSc/yLmDWWxrDPE+bPFyPLtBJB1v977rMpJkl7uCjf5IFiLEono 7abV9evWkuP2rzFMynxvRwg1DwaVT4eQ6o5tBV5pB/tLG5bqHsKze/RFcnlNbli+kDA/fcR+ 24NPttcr7eBFqrPbwM8xz1WpFUJ3VbetYSoMwHV1WHpd+OBZbtssDdbfbPNJvgGTspQQrEcz k+dQm2AP8FwlGgW3f+jhSUcWjqYFbD8ZV5F7Wf3+V78vlJCqR89iwuzXip7MCCLjNP9oYsel FlHb/hmqSn4U2//WPC6XRVKgNQZ3wlpInIYjdvn0snIkn0ebEMt5G0YmZJxkaKIRd5UofwHB NAoU90vYa6NYaZyyxnK9/PCBPVs1Ij4FaxC7sMkKyK4snoPrkiCIw9ZaB3HQLXUzpvmQhrr2 9HQBQeRlDWEw7vjanNtu1WOMjvM/1HxCu7K89drnzS8W+Go9s0e3cdVzmyFfKMjR0WXDpSjF 1p+6o5iL6N8AzfblcXsaAdChlheW6XCLVJAECgaJ9Pkr7mQg12UFyHnCeXkR01Z2rs+XgDn2 CJF1zmRdj7Rn5m/lxI2Kfj9115Ml+QeE99cVhWm4xwH2augAc57ca7Io6Il0eBYFoLxe8QdA zfaTwJOwV02pSczxiOgguPEn0g27QjNuHQF64YbrnWw3+hQbf4050uLrtxxtJIJdruuugEXa ajYAeTNir/EP5s9AqPpHopURME3kUMoLfN4lnC42e51nJkXqaXD1RiWr0BI9aTq0LjXO2F1Z 1ljdQz+cu8W1+BHuKu+OXyVXpkLBiWnEudC8cPgrpQtbgptLRyE4LAOAG4nE1v7VEbFoPMiE gaQK5H+7jPNY9kQtwKd0tijy8UveXKCHFujxf/DeA/d2w8lnP3P9uG5LzTtLoka3fx0zfYCB 26+y1Z8+ytZVr66ZcqT4YxK39Rck4y9TBL+/6DbZTZDGyRBqt+1Wv/Fn+2a7lGTqeZXZ0Wsx Zh+tmN28uabTDx1gyVnTx1JMt1giuaaPL3JAKHAuhT9dOmfXyKn6ux+ca2yA7NdgHTUTVQua R1MWoKbspCjTE+jIo4lgiKI5aH3X4Noh95+jFollnkx468xnzUdHs2aDHkvg== X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40917024" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e0WYdTfPrUqQQgvjF2Y0GCWlRNAggH+rn1cDBTk1aiyq2ZNNLQr5qN4hXHFGu1rQAPGEKy8ek5kVMKRI6yjrX7GkRPloJ0cOxMBScQVl0cVjqUrC+xbOz9tRZcxwp49EaHnLzrXp51szi9pgHvq+FksG0FIbXMo69qlUF0LZEr185awBxmFy/yUX+iUIE2YmMsUOlR7I3Krlym+9eg92HeELkXpQ/W+ZyfJbUZEiikjDqe6rybHK8GyUPQj8NJhzGGkf/5mtmyph6KUIjhlMDYK8CAoaEc0zTZr/kOFbNRpGZ3vwF6y/y7EqYW7Ghr5f4pA9GH+cO/0RsqjQ+3Vg+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1YChfSP81aZL13zYGZ4iZHk38+vOOoVLtwqftK78jk0=; b=cEsz4QVvY7FbTFGKmBRO3P+UpYszub5lM0FRXIJu4AFWRtLNeKrQCxOfhcX0r7E4bTpsVXCpST2KWYdu9fgHcIC1NfAMVuvh7SnV9sFrhiTsJHlU5ioStsc6tmxsrjR0XMP2xB96fwHdJYR1MjJLi8Jbt4mtAvfWCUE9+SxG4uZKUIVanvTYWbFuUK/WzJN+VnS1st+yUx3XDnkCraQYak36pn2mq7bRvWDuf2uFqg2/4f5YpaJx07Wad9gZyL3Br1Q7AHjsa/y2kucFW3Li9n3CzJMabA8u1sG2mUtn5utgW7auh4T1FqgkqZqpWwfSuNfvGz8h9CactiYTvasGkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1YChfSP81aZL13zYGZ4iZHk38+vOOoVLtwqftK78jk0=; b=Zz2EHG63xBds9faORxvM9t/E3L6RGWPR+JbAOegEcOos+DkpeTD7W/1Dvxwb0wXZkAAtIPhRsBwSX+T72n39ECzE1azpWCgoqddWjLaCPGWW7t1Na1tQ2cGFIeZps+7LsT0RupMnJC4r4gztPQ5cNORmYGQ3/dT4qXoI7WrYLdk= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Paul Durrant , Paul Durrant Subject: [PATCH v3 01/11] x86/hvm: drop vcpu parameter from vlapic EOI callbacks Date: Wed, 31 Mar 2021 12:32:53 +0200 Message-ID: <20210331103303.79705-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0062.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:31::26) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f474ce6b-e0e3-49c4-11af-08d8f430bb93 X-MS-TrafficTypeDiagnostic: DM5PR03MB2777: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mrIrlP88Q5KVKbY5AqredBbO1GPLqqAipp+QLGZnqOEx0rRoW83PZsUT50OdyLISod9eyRxY0jnLkSMotzFt8j+Hb9kFMqLHupRyJVOk5FlRLfN1VJAIyZzq53Lr5OKGm5Iko3vVBUKfg/VnZcrLkQlr7sex6qEl+Zw2si0bO9mu48B2B06/cLTkszvBQBQD1x7mHFjyGZK9RqC9BnTV72Rw/CHHlLNY7AQGfhRQMOH0dRfsYUwqkxLctDNzwhRfW8tXcVafVtvL2hlGK9YNoGyNumrtjPWnq8mQgB4134qazIQXst82NmkyDmG600QCeAQ7jKHolnBymlHMVzoeYCQ7K/ilSjo8feOKXhWFtpL+OX96DmsvtGqkEcw+gNPRdVjuWLG54OMz+MSBr9JbSAv5zygoqJ8qhBU2vh9jKMIn6e5oz5NzGbJZUGV4jla21wohq6n5vSiFfrMtCWYcveXdh2bkSvAi538ef6fNRQ+cadh4rad4u0IEdswYIYGE/34zQj+1N3Qa8LHxuB/4GRS7iC1rdSNBKFbcW8yX7Q9le/ppF/Ezm8vYIVh3Cg0tCfMoKt5p+ucmwezc3RUQR+3DwLKnU094FXU8mwSXUekYirJjpDbfgFENYyPnfVRMqVmYOyGvnAOSqxH7DLOyeaOTqp+jnaJYgTyuJFvcrEY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(346002)(366004)(39860400002)(376002)(5660300002)(186003)(66476007)(16526019)(26005)(6486002)(8676002)(36756003)(86362001)(83380400001)(38100700001)(8936002)(956004)(54906003)(1076003)(6916009)(2906002)(4326008)(316002)(2616005)(66946007)(6666004)(66556008)(478600001)(6496006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?5ZtxDpAKzTqTvp8AqZ5B5gHGMsLBLk?= =?utf-8?q?uq+jFhSqE3p35kCpYGaefEdXE6J909l3gTjY1otWhr1JsG5FqAKvKYhXhGP2BATsN?= =?utf-8?q?GxDgcskjyXOHOnajVzUpVanNa4mScYdZ7cCL2kQ/+NPUIxHTBBhxyP1BQO6RMSaQ1?= =?utf-8?q?xriPn+D9msMlcJnqWcyt9NWBjIqHTVZiwyD1k17vxd/KsGD5UXDit9QDA4h9Yg7gy?= =?utf-8?q?wqoupk8oD7n87WwLJeL39rsSnWpQm+dg5ZiETKK6ZSftO1gxexJkSL5fNb2lGwwNq?= =?utf-8?q?RvSsUiJ2Bk4n/VUdkwtdONnOOfN11ydhOwmhg9BzajBbuzsInOTOQ5uwCsP4zdaSG?= =?utf-8?q?9kGoBA66GAJej/GcdeXOWKGNP2QbdgfigXzKe6RdL0KG6+JGhzaNqmHRV3AOtvbSx?= =?utf-8?q?UMKMc+Zd75/4WoOdF4qrZXpAOjcG+RY5eYDKDJX/736vcjbFNgfQnXat0RwviL/rq?= =?utf-8?q?AWRgiO9Ykzwr+M4xBifzALMZmG3BpcLqPNRJAh7erdyZXM1NRf/rs25P0jge1x7XG?= =?utf-8?q?uMcz/lehttW/wXPkYVvuEVhRE1BrRbWgYRQ7vQCMvHTHVovvAOJVw7HNwLjb/26sc?= =?utf-8?q?2bMMeyt+hpt8C61gWcYSVBatRWnnw2BFPGFkHojO7FWn7Gfi7Oz0Z3yNQ6p8ZVfRu?= =?utf-8?q?ZDhhNpzBkwv0ZPYQMhvwzw9Z86rvhsC4Y42qLWyidc93ZKFnxBUwoyBeqfY7glxrY?= =?utf-8?q?brfCxOhGvd5b42IVrxwGrlUQdCLaP224nkAz/W/Vwz7xYY/9qqgqD2WnSdq5hpAg3?= =?utf-8?q?FcxaQKftI+ci46nxEEMJuhaOLgd1PP7Wbwwyvf7tGwTYI2p0Qy4u1UJDZpIFSYVNI?= =?utf-8?q?l6ZHTDY/X4Ie1onKJ1DB/i+Z+gOTidXBssNbb26x4kafY3hK7QmqCC2E0a3EVnaM2?= =?utf-8?q?UgrL49xyBVwv0bjFQXwpiE/FqhIlxRQrpj9cD2uYNLLPAw/kzp7glSvtexiQmLblb?= =?utf-8?q?75f2NyByr4JYeYwCme4KOE51OWZSppxeZBiLWlUa78iPDwDdVMOQBT9NaJxHthbmM?= =?utf-8?q?wz1Kz6HlJO2uoZdcAdJDfF7oI2M+GMFmfKS6w0y8KlSOzmfEuqAxMQzo7LjhXMAiv?= =?utf-8?q?ZFI1JhA6B3vvdrPn62FeUWkptYfjlU9hlrwlGvQAMNfUTHMng4nk1t0jnBg5dcSOq?= =?utf-8?q?6gRY6Vm9DgE3VXmfAvMRqRLJBuunCfMAw19Av+dhRCj+fNUwV3RmBHm2VdAO93jpZ?= =?utf-8?q?2h/ydMmxfmW8E5xOQc9cxywA/LUd9Jg+pu2qtfwfjiSWpvIVgTQYR5GfADQCnVoYW?= =?utf-8?q?s+oOLdW8pwIUxQ?= X-MS-Exchange-CrossTenant-Network-Message-Id: f474ce6b-e0e3-49c4-11af-08d8f430bb93 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:35:41.6346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2zJ+zYDOc4asnog8KPOMPIQFXVf6jIQ7JGLKEWexA1JRIPpVGTDMxAAjHMMqzl/jbBRtAifxzNbNtVsXshkfQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2777 X-OriginatorOrg: citrix.com EOIs are always executed in guest vCPU context, so there's no reason to pass a vCPU parameter around as can be fetched from current. While there make the vector parameter of both callbacks unsigned int. No functional change intended. Suggested-by: Paul Durrant Signed-off-by: Roger Pau Monné Reviewed-by: Paul Durrant Signed-off-by: Roger Pau Monné --- Changes since v1: - New in this version. --- xen/arch/x86/hvm/vioapic.c | 5 +++-- xen/arch/x86/hvm/vlapic.c | 7 ++----- xen/drivers/passthrough/x86/hvm.c | 4 +++- xen/include/asm-x86/hvm/io.h | 2 +- xen/include/asm-x86/hvm/vioapic.h | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 87370dd4172..91e5f892787 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -372,7 +372,7 @@ static int vioapic_write( #if VIOAPIC_VERSION_ID >= 0x20 case VIOAPIC_REG_EOI: - vioapic_update_EOI(v->domain, val); + vioapic_update_EOI(val); break; #endif @@ -514,8 +514,9 @@ void vioapic_irq_positive_edge(struct domain *d, unsigned int irq) } } -void vioapic_update_EOI(struct domain *d, u8 vector) +void vioapic_update_EOI(unsigned int vector) { + struct domain *d = current->domain; struct hvm_irq *hvm_irq = hvm_domain_irq(d); union vioapic_redir_entry *ent; unsigned int i; diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 5e21fb4937d..98e4ba67d79 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -459,13 +459,10 @@ void vlapic_EOI_set(struct vlapic *vlapic) void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) { - struct vcpu *v = vlapic_vcpu(vlapic); - struct domain *d = v->domain; - if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) ) - vioapic_update_EOI(d, vector); + vioapic_update_EOI(vector); - hvm_dpci_msi_eoi(d, vector); + hvm_dpci_msi_eoi(vector); } static bool_t is_multicast_dest(struct vlapic *vlapic, unsigned int short_hand, diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c index 351daafdc9b..2f6c81b1e2c 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -796,8 +796,10 @@ static int _hvm_dpci_msi_eoi(struct domain *d, return 0; } -void hvm_dpci_msi_eoi(struct domain *d, int vector) +void hvm_dpci_msi_eoi(unsigned int vector) { + struct domain *d = current->domain; + if ( !is_iommu_enabled(d) || (!hvm_domain_irq(d)->dpci && !is_hardware_domain(d)) ) return; diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 54e0161b492..8b8392ec59e 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -142,7 +142,7 @@ struct hvm_hw_stdvga { void stdvga_init(struct domain *d); void stdvga_deinit(struct domain *d); -extern void hvm_dpci_msi_eoi(struct domain *d, int vector); +extern void hvm_dpci_msi_eoi(unsigned int vector); /* Decode a PCI port IO access into a bus/slot/func/reg. */ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr, diff --git a/xen/include/asm-x86/hvm/vioapic.h b/xen/include/asm-x86/hvm/vioapic.h index 36b64d20d60..882548c13b7 100644 --- a/xen/include/asm-x86/hvm/vioapic.h +++ b/xen/include/asm-x86/hvm/vioapic.h @@ -63,7 +63,7 @@ int vioapic_init(struct domain *d); void vioapic_deinit(struct domain *d); void vioapic_reset(struct domain *d); void vioapic_irq_positive_edge(struct domain *d, unsigned int irq); -void vioapic_update_EOI(struct domain *d, u8 vector); +void vioapic_update_EOI(unsigned int vector); int vioapic_get_mask(const struct domain *d, unsigned int gsi); int vioapic_get_vector(const struct domain *d, unsigned int gsi); From patchwork Wed Mar 31 10:32:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FCDDC433DB for ; Wed, 31 Mar 2021 10:36:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 134D361582 for ; Wed, 31 Mar 2021 10:36:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 134D361582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103831.198031 (Exim 4.92) (envelope-from ) id 1lRYCZ-0004dy-36; Wed, 31 Mar 2021 10:35:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103831.198031; Wed, 31 Mar 2021 10:35:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCY-0004dp-Vc; Wed, 31 Mar 2021 10:35:54 +0000 Received: by outflank-mailman (input) for mailman id 103831; Wed, 31 Mar 2021 10:35:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCX-0004Zp-DH for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:35:53 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d6b4c8f5-1a2a-4f3e-a398-b4d6f00ac697; Wed, 31 Mar 2021 10:35:51 +0000 (UTC) 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: d6b4c8f5-1a2a-4f3e-a398-b4d6f00ac697 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186951; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=NV3KE9n/uXtSsphUpkD9HAmF5sKVQHJPIYSdLPj7tUc=; b=HiT10VfVApaBoPDjbJgswzgS4ajtN0BqccUSp+TcKjx84K3/aOrzKnfk +RrHOTvP/Udj9uxe9zQJIwyHMBfxVE+8KAuH4Jawisv29hycznS4d8RrS mKDZRWLOQMAJSRRjSzEVImKUfNDzGyiQdW43/F/sJ67bKvPeHeeUdRuLO k=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: E0fE6gZR48Kl3l+ZKlFokDeQ/Dhy6Y6ECTvVb+aIMVahthzYLj57uzzfAod+RjFdelFVAjz4cY uRY3GxG4Y5+DHPG0JWIl3HFagWS6Eo34HPM3daCQdKcjjq6OR6MPOSLVuEx2xx/XMRwU6P1VLl o2h/vM7EkILwbXgFEeqWD6RlZ965cZgOGoW6Uda5O3aYkNKKP3+jALSfyvIOdXvNNL94TO/SNX n+dyzV3tgKAl4HgWwWhj7xQyzjRoTxenXx5EqujU0jcE25Uby3CvqyW2r0+vAK6k77DW15ZMCK m0E= X-SBRS: 5.2 X-MesageID: 40415650 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:x0km/66VqbDf3ZJ5BAPXwRKBI+orLtY04lQ7vn1ZYQBJc8Ceis CllOka0xixszoKRHQ8g7m7VZWoa3Xa6JJz/M0tLa6vNTOW3VeAAaNDyc/ZwzPmEzDj7eI178 1dWoV3FdGYNzdHpOng5g3QKbgd6f2m1IztuuvE1XdqSmhRGsNdxiN0EBySHEEzZCQuP/oEPa GR7MZGuDasEE5/BqiGL0IIQvTZoJnznI/mCCRsOzcc9AKMgTm0gYSKcCSw4xF2aVJy6IZny0 fpuUjT5qKvs/a0oyWsrVP73tBtt/bKjvdGDMyIoMAJJjvrkRbAXvUdZ5Sy+AobjcvqxFE2kM TdgxpIBbUO11rhOlubjDGo+w783C0g43XvoGXo/kfLkIjCax8RT+9i7LgpFifx2g4bk/xXlJ 9v5Sa/saFaCBvR9R6Nn+TgZlVRuWef5UY5nfV7tQ05baIuLIV/gKY4501vHJIJDEvBmfsaOd grNs3a6fpMGGnqCUzxjy1qyNyoaHw5Ag2LdEgEotCUyDhbhhlCvjIl+PA= X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40415650" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=blXoAwoYh/Az5AzBRXyKenEOFnoKKEVMUzSYfdj9vmdLFoPYoH6Qv932DqgB01I7nOripYKYVZKk2rQPkjDmxiYwBF8otMvFEaSK6F9IFwxmdxtk1w9f/Scte4LYIdP+bo+4PKB6ZM8jtmivABJJpyNTsC7Z44N1t8/mz1LA2SCYT5Omsa3mxBtdjS6nXHUxYI+X4O64oRNjMGXWVDDENMKfuwWKne5XV97Welc3XYGw2pg7tNVckttQKbeKy2O246AbqCQeaL28+IHLhEWgatsjvXQie+PSoPaEJvdLaYkZQGrkaFsFpyuFWBdfRqHFTD1ayP0qXC+PYaOymRd63Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VFsVREZZe9qZvUSg1UZfGO+DXUpYL2DZXPRk+PVsbKI=; b=VWCTeBrqvsgaaTFFTIn/mo0cJOOmrPBrGYm+6WHOUE+YckzKwdtzPVRYG0/aaAgf7XKQJzrcbj2kFrbyK9FEMoccjwxmCrHLt/hjtypOuLJwqhy/4sEJUegGIAlI2SB1slXgkaYrR1Cz5igLVHHbiWJMWNJ62zNrkbdOv3m3e5cKANFB3s8MxHFLSCQj8ayObIjGZF9Sk5YaEb2puOb8/dxv8wC24b9QAbWi/32Zsvdk1ds04A7aJts3DJwcILPCDU+4yfQDwYk2d9OMvYR9w7AqwjZBlMtPEDZfzfNqphMeaJKewwGzqTvfV0fQkyLlleJ4wmJNuMW87H6UT5yS6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VFsVREZZe9qZvUSg1UZfGO+DXUpYL2DZXPRk+PVsbKI=; b=rb/qDlgeB1JlyyPf+W07TzbWKlf/LU4mPPfafr41+f1XhBYiRL2O0STpJW4WfEZWGpq4MrQMAiPDXx6RkXOM/QjrBGQEUILSNzXSHTVvzdrs2ipg5Xz6ait9Uw1ycyexw20tKgJdDgXmjDYmXiT8/EfvzgQIBmBr/PZ6cBdVd5M= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Paul Durrant Subject: [PATCH v3 02/11] x86/hvm: drop domain parameter from vioapic/vpic EOI callbacks Date: Wed, 31 Mar 2021 12:32:54 +0200 Message-ID: <20210331103303.79705-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0050.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:31::14) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2aa7e7b-5f5e-4d8e-407f-08d8f430bea5 X-MS-TrafficTypeDiagnostic: DM5PR03MB2777: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JzeYeKuF1xe5SUZvnjAKCGfLVRy/4rtcuqjVdtk0HZrXqxzfOS9C+LSJr3x/9ZSt9NhkZGMOfEv40Fgh9PeAbEilqJGbh0lp8Qmwj57SM/9ngs3j0AWSQQAXO8BB+HzDyP5CtcqPB7cmAf/1rspWAdMHjHoPZtTb4556JzpEzaDwHCefmecXcdERhuByVfcDRe5Ons1VfQmHMQ2rrmkBJMyQMkLGBfgZsGDm6LtXxkeG6+10Id1OJMCjTx7LHv+vC+CVc6Ds4mrndrE5Dce6NzhSMlavzyeaoLB+fxszV66nS5uEmxrZH9AfsSk6akXdF+R4G2X7YOtqywUpntYwytNmDcWK2O/wlqqotkGBKAkeS/uPKKuZ2Z+P14tDSLEOhGFij2xo9fFH/oMbV96ZMyAto7fhg4RLfmOojPAWQkxJzej1oUWWO+TwFSn8hyAluRBhs+8fT6L80jfvsQoeJa+OOe75e7xwNdyixefM847Uw8Wd1ALUS8H8hZwYNg0uD831Y0aLQkesgKlxhxoEoPDUuHtOlCBMTD9JYhnyQoNn3lFHjfkQp1nqsQ53XUjs0ldsJrmiKIvXux8LrWvwd7A6XZRVZ0PhMM8RcJ+6PPVjGasGV4cBZgHoffhsfMHb2PyBlzeF4MSQj9/aUFO+0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(346002)(366004)(39860400002)(376002)(5660300002)(186003)(66476007)(16526019)(26005)(6486002)(8676002)(36756003)(86362001)(83380400001)(38100700001)(8936002)(956004)(54906003)(1076003)(6916009)(2906002)(4326008)(316002)(2616005)(66946007)(6666004)(66556008)(478600001)(6496006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?uly5ljG/Ga7PyNovXSMxezfkCGTnhy?= =?utf-8?q?dB3Lori0Cbb1JIijvnu2go3QjoeLDG17Kns1XpNz8KDNS2GomjeuYGbdMP4MVn9f/?= =?utf-8?q?LbpMCCufG+00uMWuW3IxVJL9Y26SZBzeqTO1W+O9aMhJV8FDmbCrhMocJWjnAYsTj?= =?utf-8?q?FUeIf42illCd9f+IEZoerB8qKkZ+Z1MQIWIOHUr1TjpoxFT8mrC1h15CLISvHaczl?= =?utf-8?q?7FsSunBRwoIXwb9zR5/s/oUGM3JBzByF0bLCfvQK76d9+B3SI2IjfP0/Ysamo+S1+?= =?utf-8?q?2DK+Iz3MXWIx929x5FZhev8+j3Srd3gmR0oSIC/Z7iXSxCqbC0hT8QO6pb+AolrDu?= =?utf-8?q?mag4mQ+7KPC5AD1s/3fytWL4xD91L+P2FgbXJNZDzx4SxaHYqRstP2MUTgjmduSlB?= =?utf-8?q?Vw9L3W8V/5HNyXzffffw3bslfXQOH978F8PK6C5lLnldzrlxoFrP27KCPdqwkppYV?= =?utf-8?q?YHHBj+AyukI8UH/NZk/JmQ3/AqgyDARRrZxlctm3At8bf0kPxppxmBjJhi8bPO/wi?= =?utf-8?q?i+qRXcjZuFM/j3BD+/IlMYX4cRptXwVsU5LEA0ZSun4vZzRTcYRKqqhZDjo2aHOrl?= =?utf-8?q?QOIv0T9pv+/hkWvU3QQfEXEE0Mz72Gb/70xGn0zQ7E/gPlTKczp0iNIYhyRidgC5a?= =?utf-8?q?cstc2mONYFVBE2A9QiNEG1hS3VhOccYHqkNAW1Kis4oVTyXLk4F8HR2So6tlcU4Xx?= =?utf-8?q?K1qGfREgfOn4x/0+2pf5rf4uUAu/8hV/dbDqxnOBKjnkBWweOmj37qe+lUi1LqkHB?= =?utf-8?q?9+qTs/de+y+sH0s21Ep0ua5/z4eN7AMZQyLsgng1DldbpgtyhcNlGyJPm8yLsbvl+?= =?utf-8?q?HLY2f/WKFSfhTit83s9r6rMSEJ5vEFRorcNBuDQFX/Zc3KHR8XMKNF4/MmZ/ljg5e?= =?utf-8?q?sBMCmxn2Kics5G/6rN0l6l28w/QI9VC1P1Xf5cclVtMwtzkU03UQwQfj8auiRhfah?= =?utf-8?q?j7Y5e/+i3n3Lvh5Hpqql/K38VWRDESs1P0rWPy8bD5zMG0XJEur0RWapNNucEsf26?= =?utf-8?q?+IAZjcXm/TxRsKuPouSXu+3rcajp2HF2naDs0GwCY5WZPDEldsgkNBv1+ZTvuR7Hc?= =?utf-8?q?p1UZxg6g7m5nrvBT0Mifh8Y2VMrt89v405XsVWqMHJhB1Swg/Pgap1dAYBdCZOW1H?= =?utf-8?q?tVUVd27cGZO/DwzNtCgdEzjsT/3P3MLZkq/dW+vIMxQ4FjbKxqGfo+IqCbEJLrVZh?= =?utf-8?q?4nLI53jfkJDhvfLoKWr0W6mxYBaxlektMMG8dMrQNJGxKa+RgdwieJXEQrEBhpTgE?= =?utf-8?q?MXaPHcGS1o3IHO?= X-MS-Exchange-CrossTenant-Network-Message-Id: c2aa7e7b-5f5e-4d8e-407f-08d8f430bea5 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:35:46.9015 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nb25nqCrGbm9AFGTWtwpohMLth2F2FDioSTNaJq9OP/+XmmSmjP9KMDigNXvgYtuYXhUBqv2iRp3u0BhabsL/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2777 X-OriginatorOrg: citrix.com EOIs are always executed in guest vCPU context, so there's no reason to pass a domain parameter around as can be fetched from current->domain. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Paul Durrant --- Changes since v1: - New in this version. --- xen/arch/x86/hvm/vioapic.c | 4 ++-- xen/arch/x86/hvm/vpic.c | 6 ++---- xen/drivers/passthrough/x86/hvm.c | 3 ++- xen/include/asm-x86/hvm/io.h | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 91e5f892787..dcc2de76489 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -284,7 +284,7 @@ static void vioapic_write_redirent( */ ASSERT(prev_level); ASSERT(!top_word); - hvm_dpci_eoi(d, gsi); + hvm_dpci_eoi(gsi); } if ( is_hardware_domain(d) && unmasked ) @@ -541,7 +541,7 @@ void vioapic_update_EOI(unsigned int vector) if ( is_iommu_enabled(d) ) { spin_unlock(&d->arch.hvm.irq_lock); - hvm_dpci_eoi(d, vioapic->base_gsi + pin); + hvm_dpci_eoi(vioapic->base_gsi + pin); spin_lock(&d->arch.hvm.irq_lock); } diff --git a/xen/arch/x86/hvm/vpic.c b/xen/arch/x86/hvm/vpic.c index f465b7f9979..a69aecad912 100644 --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -235,8 +235,7 @@ static void vpic_ioport_write( unsigned int pin = __scanbit(pending, 8); ASSERT(pin < 8); - hvm_dpci_eoi(current->domain, - hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); + hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); __clear_bit(pin, &pending); } return; @@ -285,8 +284,7 @@ static void vpic_ioport_write( /* Release lock and EOI the physical interrupt (if any). */ vpic_update_int_output(vpic); vpic_unlock(vpic); - hvm_dpci_eoi(current->domain, - hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); + hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); return; /* bail immediately */ case 6: /* Set Priority */ vpic->priority_add = (val + 1) & 7; diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c index 2f6c81b1e2c..a9256e7ef51 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -911,8 +911,9 @@ static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) hvm_pirq_eoi(pirq); } -void hvm_dpci_eoi(struct domain *d, unsigned int guest_gsi) +void hvm_dpci_eoi(unsigned int guest_gsi) { + struct domain *d = current->domain; const struct hvm_irq_dpci *hvm_irq_dpci; const struct hvm_girq_dpci_mapping *girq; diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 8b8392ec59e..4f294232fb7 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -101,7 +101,7 @@ bool handle_mmio_with_translation(unsigned long gla, unsigned long gpfn, struct npfec); bool handle_pio(uint16_t port, unsigned int size, int dir); void hvm_interrupt_post(struct vcpu *v, int vector, int type); -void hvm_dpci_eoi(struct domain *d, unsigned int guest_irq); +void hvm_dpci_eoi(unsigned int guest_irq); void msix_write_completion(struct vcpu *); #ifdef CONFIG_HVM From patchwork Wed Mar 31 10:32:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 079F2C433C1 for ; Wed, 31 Mar 2021 10:36:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 778FA6198A for ; Wed, 31 Mar 2021 10:36:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 778FA6198A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103833.198043 (Exim 4.92) (envelope-from ) id 1lRYCd-0004hg-C9; Wed, 31 Mar 2021 10:35:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103833.198043; Wed, 31 Mar 2021 10:35:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCd-0004hW-7v; Wed, 31 Mar 2021 10:35:59 +0000 Received: by outflank-mailman (input) for mailman id 103833; Wed, 31 Mar 2021 10:35:57 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCb-0004gV-L0 for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:35:57 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 44e71fb5-fe1a-4cb7-891e-c4233cdb117e; Wed, 31 Mar 2021 10:35:56 +0000 (UTC) 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: 44e71fb5-fe1a-4cb7-891e-c4233cdb117e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186956; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=uZL29ugOlkoo4WkuuUBU+vjfeGVoGnql4+FwdjwuYkw=; b=cMcaf7jlRyPTxy9fC5T1nSuWXaaUmgmAjUEacUNGOoi6qVx+8IH286RE KP/8vA6RJi+nBppWs2t6QwnkruGZIYcuSlRfTJeyBMZ3F44CvfCOOZkjH a4MwZ0YM2XGK3mCQ87Vg7Te6B8MRaOk3yS8gcFDORedE6QxOIw22bXxEd M=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: /uvVyBv5xVnGakZuFeRVMy4mY9cyezBPFJig4mB6tRWhyGbcU7vPA5DcqVjPIa4nSnJPdW0lSY gCPlH/uacWa2Gk1Rkz+mW0Y8rJ4zxosMUqY1fmgKLhywQAPm9CLUAwAZlT32y9wG2/UcVyg7zX SE/COgEiplotmXfkQHK8D9Sk0FAZUM+Ch5Jo1RrIQu9aqAcflIV1m8bqp6qtpUbgZ3IlkYMEd5 3FbUfV0iU0K862wjTWrMLtpROdrsLy3lDg5O+ZdusFa9DbUbWFjZf3trfo/Kx81ZSuH1IkFfIk VbY= X-SBRS: 5.2 X-MesageID: 41994558 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:B5fhqqtFUXAdGj05Gn3cyYaB7skCrIMji2hD6mlwRA09T+Wxi9 2ukPMH1RX9lTYWXzUalcqdPbSbKEmwybde544NMbC+GDT3oWfAFvAG0aLO4R3FXxf/+OlUyL t6f8FFYuHYIFBmga/BjzWQPM0nxLC8npyAocf74zNTQRpxa6dmhj0JaDqzNkFtXgFJCd4YOf OnhvZvnDardXQJYsnTPBBsM9TrnNHXiIngJScPGh9P0mKzpAm14733GQXw5GZ8bxpzx94ZkF TtokjCyYiI99q6zRLd0GG71eUtpPLRjuFtKebJpswcKjDHghulaoJ7S9S5zU0IidDq0nkGup 3hpAohItRS5hrqDx2IiCqo4SbM+nIP7GLv0lCRi3eLm72HeBsKT/BvqKgcVzmx0TtFgPhMlJ hl8kjcir9sSTTHpyj578igbWATqmOE5UAMvMRWs2ZSSuIlGdhshL1axmx5OrEaEhn37Yg2ed Med/301bJtfVSWY2uxhBgI/PWcGnA6HhKxSkMfoMCi0z9PgHBjz0cDrfZv50s9yA== X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="41994558" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lhQY8Q/l2c+6iIvW71SMpYAVrLVHsqARZo9cog2+8XzZhmUbyv0ZETFZy1lrUswKxoovVEbOIhbPxVeGXgCgNOTiIXcqt9a2kyTu55852tJ9TmNlTjsTfu228ZK5FfY0pPVO2QCmELgxDnyrX79LTwBJNYG9fTkTZQYn1mdBPKa1LHPbJWnda+YqRbSdllg0QE5yhx3rk1qmgB615NTr/RPb4cwsPLAn4eDdQlX73k2igQuvuLWZ3liqvLNbBLkcwNNYNKsIPhzslOK9knthU7MYlVIdCJur7Jp8Dcz4Ov+HOJFPFh1zML1dqd1ntsKLU63Nl3H4zHq+GWy6ubp3xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uZNy/L5pNGQXMad8B2V5JHLEH+vnc9PVuVRiLVFoWBc=; b=gAJ2rBDFAFszOJyQBarAM2F89ax9WwK3ixGwi4oM38jCWbvzOoB43NiSQXrryQ0TQkkeKtXI3KobNzi6Y7KoCSNc5hIPj72HNEGB+5F3dhQW7CDj/EIoAhZm6uPmU1RKt0GA//lBMmDqV8CM6T5WbqjiuVeHZ3tOqFsgKSa4EXVSFpQ+wFhk0IC7CtR9/NQ4RuYfn730C2q5VtfDqJS6+NsAR+9EDlPd0WIzwL6dhicCfSaa4DwEQdNZSCDO2t/uL6ODZ2mncAZWlLFSnvHmg953otOpvMQeBs/q/hbBryHw/x0oOpHbHOLIRfd0jYgFMmBIMhPB3YmK6uXyRSUURQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uZNy/L5pNGQXMad8B2V5JHLEH+vnc9PVuVRiLVFoWBc=; b=FpVkjNC/CUc/BLLNsCdcUqyK64HwCy/rUvncXKF+5SF4ChspWMqN0NqM8DYNTd1paPGjbKynepgtd52wFNFx/Lyn1uRi6U+bgQa8T3Etozw8jXQt09Xgug4PnuzLkqtmZcI8WWXsEO+deOyh+LgmJMlmMWk/WQNfGK83ECEC0o8= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 03/11] x86/vlapic: introduce an EOI callback mechanism Date: Wed, 31 Mar 2021 12:32:55 +0200 Message-ID: <20210331103303.79705-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0152.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::15) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 849cd698-cfa6-4f51-9f0c-08d8f430c258 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:506; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 978tVbIdC4b7xVB7qTjvrvvOkPJqj1euY03Fn+Y3BPKz73P4rRIBvxmu379v1eJuNtfUg2PLMd7kl3kXmES9+umdE2xIgWXFUloHXoydg+z4fKWUmrrbTnRVZv1yvusFt9FAj4ouZGz/y/luXOEyafVruUDQgRtwEJxFRjrmqOdK+tgLpPK4YSyYixeCTgte6vWTkbM9FI//esy4PeNdHJeFKkAzs92UpPbSZ/vczwGcSY/EgVTiyl4B8K6ERrGewib1Y/9kwl1d3oYEUsn7igc3PjUOx1wekVq1FB0q28v0lZ3iXP57kDN6NZQE52KVaMv4m8PiQoLcZv26RFQ1xoDeMoqvoqRSmhWd8zzWTOGGvuwjcNps8ZYB4PUPlpL9Eu6918M9buKzR1EQuM5bUvq8PbYVS+PrAV8OkrBUsan+BJTAlaTisrd+61UFRsIEmUhrMVALZNClveNfrxKwry1rdsKIz1pJ3WMe2p3fGPXA9QROrFbHTxs0+BtZQK+nMEcy6Mv6h6na2CdOyXY09+U5aQwAhXstRo91KDnEGWbzisno8SzrRLQMdGe+amcX88H9mAB5hUbAXJpiYk6ezizPKNTznEYDV8M/6n26EyuUTC5ex1guQEUGan1ZR/wi27ebaAidDUw0RuDlDOQwfkjbCWuceFb5W4hqdiBIIzY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?1W29Eto/aBjRpJyU1UOXis+CyGIAjU?= =?utf-8?q?D8n1phDIwPOhIZ1OKTN4UAYnbEwOIPgxW7xOGiy+RmxicwtuYrOFKHrm7/eK8Hc8k?= =?utf-8?q?ZEITFKfH2WhO+NC7+BylVtLgSgt+J0ePmnjU1eVxLY8i3eedkX8WLc8ucQcVjGr8Q?= =?utf-8?q?EtzPxXDbpfhM1BzfcROSmZ4gdF2gCajn+Xg4kuux/N8Pz0RBjFx2PZ5TkClU4iI4i?= =?utf-8?q?oxoIiwJGQpfuO+Ai5ZvCKJ93J6o5CD2LHTIjFOLkMreNcOyqDCndv7tj7Afh9j5m3?= =?utf-8?q?Hrji2rdFLFn4dlst0hiJ3kWkvM4Ha40V8QeNtPh+7fOffpfRLq3putktfp6brNcFB?= =?utf-8?q?e4FSe5eSP/7nJOWbWFHuQjEJf+qZmlbsU5qPLoNzVLssjFSwNz2gNepMk5EOO8Npv?= =?utf-8?q?MLo0DQa+FnNOwLZyw1H0z2ieCr/D3fsVkkuo59enNWn4eREUDGOrukDD18yVPuZRW?= =?utf-8?q?3+NalXeQDhg7BU+M8UEVRcRTYtBvf85W1WTsWi/i4fEstmDtWrcs+L+d9DxtHiyv+?= =?utf-8?q?ZsbCzLnLrPfddqwQHoh/fYzD9C1Uu0/uMhaYNMPEzaw96c4anckuXJdMQ386ORCGp?= =?utf-8?q?WN4iNHPEtaPRaSK4itMZYWFTf+AUrmntA+c5wEfb2bwn10CbdwA0yxi6zsAgWaojU?= =?utf-8?q?KHn9yvkWFRXZuiTAl8KbtJKNqj7mq8Xp6oVq8N0z2w3deYDa3evA4DvQWa820VF9h?= =?utf-8?q?bsfUTswHYpz5PFCJ99wLxFscnPSqA0FXEtMEBsj1VmrGASChgMZRl5B7QEOAdy8ow?= =?utf-8?q?8+ztXa61B7P8ivb2Ja8+SmZfj1ofalnlCVTbYsj5zAF5FY/E118HxG7bt4beSszOi?= =?utf-8?q?X/wlEsjosTonn6XdOIMEaj+ICZ6mbH3TO4IxdizDEgvSwRiGYmgknBvWmZaI9d0rh?= =?utf-8?q?gaVRzeMmpeuwRB1HlSZHOOahox8wfpCjYAKkH9dSkXdSQCEhRW3B7tzZXzR3ig4bT?= =?utf-8?q?fWUHJTVNr4lFcIHqKkXIet5Eynb42LJ3lZz83tAUz2G6dwCNAJ4dW3rf97SoGfSES?= =?utf-8?q?iH3l2jCxn3njdXsQmT1AqOrcRjD/RtcOpHY7VM1Mwu6rwzAua8zgK3v3OWPChDvmJ?= =?utf-8?q?xKXqptLHnZpgP0oHZDETfaUib5vS60PQ4odZlT37OFdP/CJHQw5GSh2zhISnBsSE0?= =?utf-8?q?mKm/wfGdIRmWnzp6I7NcsNVsb2Wo6+sckE0+ZIdL73ShaIgR3ZvsPyj3Is2OHqIZW?= =?utf-8?q?lB5sE46gmiekCPA1AN9eMJYUUScXSmt/La1tEuISu3JkV+0DkvmBg71tbBnkQecPL?= =?utf-8?q?FUX+P7S1jB213x?= X-MS-Exchange-CrossTenant-Network-Message-Id: 849cd698-cfa6-4f51-9f0c-08d8f430c258 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:35:53.0006 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Uk7sJxrigTALmRmpuIWDkmH+7wdVt+PT3ExT0sWxHlJOrqFVHvkSft46g9fK+2jhBxH7VImo50T1kwTlgc9S1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Add a new vlapic_set_irq_callback helper in order to inject a vector and set a callback to be executed when the guest performs the end of interrupt acknowledgment. Such functionality will be used to migrate the current ad hoc handling done in vlapic_handle_EOI for the vectors that require some logic to be executed when the end of interrupt is performed. The setter of the callback will be in charge for setting the callback again on resume. That is the reason why vlapic_set_callback is not a static function. No current users are migrated to use this new functionality yet, so no functional change expected as a result. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Fix commit message typo. - Expand commit message. - Also print a warning if the callback data is overridden. - Properly free memory in case of error in vlapic_init. Changes since v1: - Make vlapic_set_irq an inline function on the header. - Clear the callback hook in vlapic_handle_EOI. - Introduce a helper to set the callback without injecting a vector. - Remove unneeded parentheses. - Reduce callback table by 16. - Use %pv to print domain/vcpu ID. --- xen/arch/x86/hvm/vlapic.c | 64 +++++++++++++++++++++++++++++++- xen/include/asm-x86/hvm/vlapic.h | 18 ++++++++- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 98e4ba67d79..851a1f5bd6c 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -144,7 +144,35 @@ bool vlapic_test_irq(const struct vlapic *vlapic, uint8_t vec) return vlapic_test_vector(vec, &vlapic->regs->data[APIC_IRR]); } -void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, uint8_t trig) +void vlapic_set_callback(struct vlapic *vlapic, unsigned int vec, + vlapic_eoi_callback_t *callback, void *data) +{ + unsigned long flags; + unsigned int index = vec - 16; + + if ( !callback || vec < 16 || vec >= X86_NR_VECTORS ) + { + ASSERT_UNREACHABLE(); + return; + } + + spin_lock_irqsave(&vlapic->callback_lock, flags); + if ( vlapic->callbacks[index].callback && + (vlapic->callbacks[index].callback != callback || + vlapic->callbacks[index].data != data) ) + printk(XENLOG_G_WARNING + "%pv overriding vector %#x callback %ps (%p) data %p " + "with %ps (%p) data %p\n", + vlapic_vcpu(vlapic), vec, vlapic->callbacks[index].callback, + vlapic->callbacks[index].callback, vlapic->callbacks[index].data, + callback, callback, data); + vlapic->callbacks[index].callback = callback; + vlapic->callbacks[index].data = data; + spin_unlock_irqrestore(&vlapic->callback_lock, flags); +} + +void vlapic_set_irq_callback(struct vlapic *vlapic, uint8_t vec, uint8_t trig, + vlapic_eoi_callback_t *callback, void *data) { struct vcpu *target = vlapic_vcpu(vlapic); @@ -159,8 +187,12 @@ void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, uint8_t trig) else vlapic_clear_vector(vec, &vlapic->regs->data[APIC_TMR]); + if ( callback ) + vlapic_set_callback(vlapic, vec, callback, data); + if ( hvm_funcs.update_eoi_exit_bitmap ) - alternative_vcall(hvm_funcs.update_eoi_exit_bitmap, target, vec, trig); + alternative_vcall(hvm_funcs.update_eoi_exit_bitmap, target, vec, + trig || callback); if ( hvm_funcs.deliver_posted_intr ) alternative_vcall(hvm_funcs.deliver_posted_intr, target, vec); @@ -459,10 +491,24 @@ void vlapic_EOI_set(struct vlapic *vlapic) void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) { + vlapic_eoi_callback_t *callback; + void *data; + unsigned long flags; + unsigned int index = vector - 16; + if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) ) vioapic_update_EOI(vector); hvm_dpci_msi_eoi(vector); + + spin_lock_irqsave(&vlapic->callback_lock, flags); + callback = vlapic->callbacks[index].callback; + vlapic->callbacks[index].callback = NULL; + data = vlapic->callbacks[index].data; + spin_unlock_irqrestore(&vlapic->callback_lock, flags); + + if ( callback ) + callback(vector, data); } static bool_t is_multicast_dest(struct vlapic *vlapic, unsigned int short_hand, @@ -1620,9 +1666,22 @@ int vlapic_init(struct vcpu *v) clear_page(vlapic->regs); + vlapic->callbacks = xmalloc_array(typeof(*vlapic->callbacks), + X86_NR_VECTORS - 16); + if ( !vlapic->callbacks ) + { + dprintk(XENLOG_ERR, "%pv: alloc vlapic callbacks error\n", v); + unmap_domain_page_global(vlapic->regs); + free_domheap_page(vlapic->regs_page); + return -ENOMEM; + } + memset(vlapic->callbacks, 0, + sizeof(*vlapic->callbacks) * (X86_NR_VECTORS - 16)); + vlapic_reset(vlapic); spin_lock_init(&vlapic->esr_lock); + spin_lock_init(&vlapic->callback_lock); tasklet_init(&vlapic->init_sipi.tasklet, vlapic_init_sipi_action, v); @@ -1644,6 +1703,7 @@ void vlapic_destroy(struct vcpu *v) destroy_periodic_time(&vlapic->pt); unmap_domain_page_global(vlapic->regs); free_domheap_page(vlapic->regs_page); + XFREE(vlapic->callbacks); } /* diff --git a/xen/include/asm-x86/hvm/vlapic.h b/xen/include/asm-x86/hvm/vlapic.h index 8f908928c35..c380127a719 100644 --- a/xen/include/asm-x86/hvm/vlapic.h +++ b/xen/include/asm-x86/hvm/vlapic.h @@ -73,6 +73,8 @@ #define vlapic_clear_vector(vec, bitmap) \ clear_bit(VEC_POS(vec), (uint32_t *)((bitmap) + REG_POS(vec))) +typedef void vlapic_eoi_callback_t(unsigned int vector, void *data); + struct vlapic { struct hvm_hw_lapic hw; struct hvm_hw_lapic_regs *regs; @@ -89,6 +91,11 @@ struct vlapic { uint32_t icr, dest; struct tasklet tasklet; } init_sipi; + struct { + vlapic_eoi_callback_t *callback; + void *data; + } *callbacks; + spinlock_t callback_lock; }; /* vlapic's frequence is 100 MHz */ @@ -111,7 +118,16 @@ void vlapic_reg_write(struct vcpu *v, unsigned int reg, uint32_t val); bool_t is_vlapic_lvtpc_enabled(struct vlapic *vlapic); bool vlapic_test_irq(const struct vlapic *vlapic, uint8_t vec); -void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, uint8_t trig); +void vlapic_set_callback(struct vlapic *vlapic, unsigned int vec, + vlapic_eoi_callback_t *callback, void *data); +void vlapic_set_irq_callback(struct vlapic *vlapic, uint8_t vec, uint8_t trig, + vlapic_eoi_callback_t *callback, void *data); + +static inline void vlapic_set_irq(struct vlapic *vlapic, uint8_t vec, + uint8_t trig) +{ + vlapic_set_irq_callback(vlapic, vec, trig, NULL, NULL); +} int vlapic_has_pending_irq(struct vcpu *v); int vlapic_ack_pending_irq(struct vcpu *v, int vector, bool_t force_ack); From patchwork Wed Mar 31 10:32:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ED4AC433DB for ; Wed, 31 Mar 2021 10:36:15 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2D4D96198A for ; Wed, 31 Mar 2021 10:36:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D4D96198A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103834.198055 (Exim 4.92) (envelope-from ) id 1lRYCk-0004nm-Mr; Wed, 31 Mar 2021 10:36:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103834.198055; Wed, 31 Mar 2021 10:36:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCk-0004nb-Io; Wed, 31 Mar 2021 10:36:06 +0000 Received: by outflank-mailman (input) for mailman id 103834; Wed, 31 Mar 2021 10:36:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCj-0004n7-NJ for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:05 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 36f13894-7e30-4be7-b5d6-7f162e5a4861; Wed, 31 Mar 2021 10:36:04 +0000 (UTC) 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: 36f13894-7e30-4be7-b5d6-7f162e5a4861 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186963; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=SAMetwL225xAPJrGDUL/huf4ma4jzM1uF1a4Ewpv1GI=; b=fmFkDtuxxqJTuYSGyA2G/qx8qYNb0C17Ek/zlQ1R1zbR+SH1LB4l96fM 4rsqCbtNV6+UXHxs/PZ7GYKw3ixesZh2+G3u/wAFFU9l/Z/CwJU06ccDa f6qLCFLEc3jLm+NKlLIml30nER4CUqGFCIPfPSW7la/VfY6OGDF2Thge3 o=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: mMzDO/UtqfEMR85hIoZGLRQ3Kir479SPvJtCWN1oKs3VaYJXFfY3VFlBJhwbr3a14m++TGZQXH 5lQxI0mZyBX2xgT0wWdpNmfCHAs7UO9ISdWCCJFj3hKYG+C5dREjkDdLznq0LkVJzujhgATXOg lUx8WgENIUiOSP5K+/LACYNfBeyBS5n0ukYeMjFby6tiLM+R+qetV1LaS5bjLh0OHmBr8dNnxU Qpa5yRVW8poVoXujUPFjW/Seh394NS/bxymJc/ZkSxKEYF3YBuknzrmpxpCxI8uBbXOwqcoomx oAY= X-SBRS: 5.2 X-MesageID: 40526842 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:yz5w+6+g3WNDQYI+MSFuk+ECdb1zdoIgy1knxilNYDRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsS9aFnb8oN45pRUAKe6UGDdyQ6VBaxBza+n+T3vHCXi6vVQvJ 0LT4FSAMD9ZGIUse/U+w+9euxP/PCi0ISFwdjT1G1sSwYCUdAD0y5cBhyAGkN7AClqbKBYKL Om6sBKpyWtdB0sB6zWOlA/U/XevNqOrZr6YHc9bCIP0hWEjj+j9dfBYnul9yoZOgkv/Z4StV Lrvia8zaWlvvG9xHbnphXuxqUTovTN4J9uAMSNj+IcNznjjB25Db4RJoGqjXQOj8yErHosjd nQszcsVv4Dl0/5TyWOjjbGnynmzTo05HfpxTaj8ATeiP28fh0WIY5lp+tiA3/kwntlhv5Q+u Z3+ljckJxtARbJjE3GlqD1fiAvrGWYiz4fi+IJ5kYvNrc2WftqgqE02lhaK5sEFDKS0vFdLM BeSPvR4/tbajqhHhbkl1gqxNStW0I6FQudTn4DvdSI0yNXkGoR9Tpg+PAi X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40526842" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PYFNRO2v9PQNta0i9/xKKWtOyUexGq4WJb15ZY3awq2ZmoS68E7k0nA4eVyDjPg9tySdeeZmNhiozWB10wX5D3a4Inny4pSUNnKrNuWT+7dwlgIP5Q9Z6g4Ekj/tPpgI0S7O5eHXd+9bH61Wzgda12X4DUbbDXs7N4TkbGxzufg61CctqBNw8F4uX9ZQjlIsEcaD1zQDIDtrkOxPbLqr7eovvTZFeNW796713lza+MI2TJ/UwgcKuo8FYfZO2tquRkqDc0mcLSf8y0BokOsTlju1Rc69gVJFdD3oL20cPyOnStX0jF/xRyRhjZ3zTSK5WVIWEfporiSuTxvukH1onQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oExx38XePN+e7ZWQr4jQrYxJher8CBXgUSz66AMKv2I=; b=hsgtQ7cFnU5YYlHSP17fZ3F0+FgXNYY97fmI/k1wGINLuf1pXNO3cGzYjiIPIjN3IsgQnzO6Re/DdHnm09Q/xWK9esAlGWyr8LU0BrH0KGv4ky8m5EwN5ALHYpRNZrJ1zP/i1iOsJ/gjgA2abgONOXwkgjEqz+ezsIdIKfZybnEWbR9c4EC9rtG56Uzgv07fVRuTayZxJGjWDdefNuLJ0BJMMroiI8SpOraK8Z/a7erBxQ8EFAzNmtI6wia6sqG2JSCx9nQMLm3Pjs9wjEiYhqLIqpEuU0X5s+V+ty+9TVsjqL7B6Mxq295XGGoNP8leSIcFFgcciszWBOzvE5vOdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oExx38XePN+e7ZWQr4jQrYxJher8CBXgUSz66AMKv2I=; b=wg62XuQn993CLgDTML37U2+AifsWMQQCrPu090gBmPGLgM/uVxVrATw6Cq6Hi8xxoEFFuESe6vBIpishrZGhzZLZOuyczzN4hOA9bQH8C9TQ1eVTxvlHktI0DgUQll/pRxL0QJra/jKSBYcb+qtxLBKMxgOcwhzcQUXvTAieZrg= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Paul Durrant Subject: [PATCH v3 04/11] x86/vmsi: use the newly introduced EOI callbacks Date: Wed, 31 Mar 2021 12:32:56 +0200 Message-ID: <20210331103303.79705-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0126.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::18) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42ff27b1-56fe-4a67-8066-08d8f430c62c X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QE/xhWlPvdNviFTXrhyJYz09KJm+WG6fBc/zLhEBQwXxez6QSWlaL47RSrXUtZOxaG7xItKIcwJWSMasW5W4M25xb5yI5KgH5P3WiuyhQUVSsbvk834Ui7vEQ0rs4eP2L3VO70PSJfRxHJDdR61/bswqCvTKewVNUHwgHnDDsB58OoGYqnrVlMEyaYKp1bgftwdk9sD/UNEfnhhdnBlxeZOwXa5Vf0gz7h/YFETxVrwvaovdswxK/naoRY0RUkwqEo1NYb/uXINhUw7CrdWXD+o9n+BYt4muKnOKQAXNgHCqO5DX/nvurkUlcJMTDlFqFIPGGCCxm8Lk15i3umy0rSi6MSqZVYnFCcT7h4ugM3uXu79If/e7KXyJ63vZKBcRoFRG0TOaJNXswdfNeSZr6ekve/KpwsDJbamhj3+peQEao/tfCFxScOU9ioaPvuMemJaVSY8cUaihRZXRIyzUi81K4x0k26TBR/tcezaWi2N+iM0wxVfqsezB5huL1PoClfdTLa/E/XbISlT3elkkiY4fIuvPA9Cl428lsgZIWCG6zBOpeNKsNue+8scC3EXJWOEJjoiX//nMuawPorCcbUSU0MMbDEFQXSX8PEB8Bz+gpc7/dFRrWgU6Boz+yzbgiin/VzriFzgcPnH7AJ0BSy1uwwiGh3GlTS06nd7DOe8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?dj8Uii/3pkglhjBhzpnKnKWgjAfWw1?= =?utf-8?q?TH2J0Luy/dqm7GMboYTsExu3TN+9Uefmy/CHTtziL0qXQr0gKuRrX5lzBVXaWUzDT?= =?utf-8?q?/Gv+//V07J5m8fK5bz/4U8K8IPI+/inNQIiFDBmw1lc10eki1a+dzpmldq5k+WSKL?= =?utf-8?q?gt41j6tRNi2NFnE1LJwyJKLvtZkkkcvFxaXq+kE6NjIcpovcIsBdOQM/XBiIqsYRS?= =?utf-8?q?+KtCAT9OiH3FDoRFZpzCzC0OlCjAi34Ob23Lwl1LiIvo3CylFbxQ+0FgV5DGrqQer?= =?utf-8?q?JUU0+0EH5ELKdSI+W8fQUICpzTJ6LbNLN/+XyT3Ajc6sUYDS8AeS2Na5eSxes3ayT?= =?utf-8?q?wYzjzMFIY5nSuBhYWm4tWGzEHRTyd3q9NktSHhhB7ZAAQpk421CLOtaH74vJ5ZdjV?= =?utf-8?q?BBt+Oh1kpMgF2Tcm+dbqQwX4QPj3+Z9r5KV4hx7KPM59bmFfYSg9ZtSRG+MWFNHVJ?= =?utf-8?q?LhyaW58rH6mIxW5Ux/TOiUorfGgPR6Ow8VAZ+V8vwLXXPFXXjGk9C5PXPqXNvcJg9?= =?utf-8?q?Ki4cndFYANfyGPaUGGO+yrZBURUJKHpqzZSiv/fjVyYqWqQiwqCsNCErsBoMCMysC?= =?utf-8?q?AI2evgv7rmRSoocrhRMubwYk9qLX+WKC/e6roMww7DWKUZCSmZKJyE6LzVkhaV12B?= =?utf-8?q?vrfRysNazOawCj2flXjhdsg35+XvMmqDVNFnG5zBolL/9IidNnTVp9rbSeoOJAhsd?= =?utf-8?q?yuvFTvFVwu1bNojl3nOXbCIOleb1ClGk94yqTf8PoRCLADzCP45CE9IcoD/+weUk8?= =?utf-8?q?7MzPnrZ4SFtnQc1iNnVma2p50pCGzvOxtGdKGyy4Q3QMbmUVEaCPufyorIhsMrE0O?= =?utf-8?q?VemqBTJkhEEo5v9wLET7dIujs/pzZmqvQJEuEK9q6POJZg3cs5Ad2dBElS4YQwDzK?= =?utf-8?q?3beDVSKyPC+8z9yAdgiGyJ5PMPZojO6oGvSbDvxpdMEs/GMGHgX/OCnTixpeGPQIq?= =?utf-8?q?H0bbAToqddD3Fx+Iwic7/28dpKq2XtINJpnE+mKbQMmrlHFTuSrm0nSlG/Dksz9tp?= =?utf-8?q?/KUUN7HggGkvRBXSATuqjyso53To4MgnNb+kT61XJc0vgh2lwnNmYNtNjcevcr0+T?= =?utf-8?q?xKK/+DJ3JAFn7Vh53s8GLETqmV+B6hn1ex2mQDME/lfm5KoZDVtIeYzv4k4w5mS7U?= =?utf-8?q?oY7XPpvecNMTAXgOSWiqhOjOtgXtkI/ITlqkRHU05VE0Ea4fEhCJ9c3jg2Iryi30r?= =?utf-8?q?tSaZ8cxPnkZa5uNg35kSmon/Zurq18ixRTfFd97QNg0cMppcc4jevI6OhcJGHun60?= =?utf-8?q?fxIJDAa45hcWXc?= X-MS-Exchange-CrossTenant-Network-Message-Id: 42ff27b1-56fe-4a67-8066-08d8f430c62c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:35:59.4184 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JHaqRcPZ7IXQIMl0WsxuGNv6e5Ct6+k4NQVuYVwumLEXRaaCJ7dK3w8+CgrvgCdOAQZrszudRRmmgvMBtTyLEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Remove the unconditional call to hvm_dpci_msi_eoi in vlapic_handle_EOI and instead use the newly introduced EOI callback mechanism in order to register a callback for MSI vectors injected from passed through devices. This avoids having multiple callback functions open-coded in vlapic_handle_EOI, as there is now a generic framework for registering such callbacks. It also avoids doing an unconditional call to hvm_dpci_msi_eoi for each EOI processed by the local APIC. Note that now the callback is only registered (and thus executed) when there's an MSI interrupt originating from a PCI passthrough device being injected into the guest, so the check in hvm_dpci_msi_eoi can be removed as it's already done by hvm_dirq_assist which is the only caller of vmsi_deliver_pirq. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Expand commit message. - Pass the domain as the callback data. - Remove the check in hvm_dpci_msi_eoi --- xen/arch/x86/hvm/vlapic.c | 2 -- xen/arch/x86/hvm/vmsi.c | 35 ++++++++++++++++++------------- xen/drivers/passthrough/x86/hvm.c | 8 ++----- xen/include/asm-x86/hvm/io.h | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 851a1f5bd6c..10b216345a7 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -499,8 +499,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) ) vioapic_update_EOI(vector); - hvm_dpci_msi_eoi(vector); - spin_lock_irqsave(&vlapic->callback_lock, flags); callback = vlapic->callbacks[index].callback; vlapic->callbacks[index].callback = NULL; diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 13e2a190b43..3da0a2261fd 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -44,11 +44,9 @@ #include #include -static void vmsi_inj_irq( - struct vlapic *target, - uint8_t vector, - uint8_t trig_mode, - uint8_t delivery_mode) +static void vmsi_inj_irq(struct vlapic *target, uint8_t vector, + uint8_t trig_mode, uint8_t delivery_mode, + vlapic_eoi_callback_t *callback, void *data) { HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vmsi_inj_irq: vec %02x trig %d dm %d\n", vector, trig_mode, delivery_mode); @@ -57,17 +55,17 @@ static void vmsi_inj_irq( { case dest_Fixed: case dest_LowestPrio: - vlapic_set_irq(target, vector, trig_mode); + vlapic_set_irq_callback(target, vector, trig_mode, callback, data); break; default: BUG(); } } -int vmsi_deliver( - struct domain *d, int vector, - uint8_t dest, uint8_t dest_mode, - uint8_t delivery_mode, uint8_t trig_mode) +static int vmsi_deliver_callback(struct domain *d, int vector, uint8_t dest, + uint8_t dest_mode, uint8_t delivery_mode, + uint8_t trig_mode, + vlapic_eoi_callback_t *callback, void *data) { struct vlapic *target; struct vcpu *v; @@ -78,7 +76,8 @@ int vmsi_deliver( target = vlapic_lowest_prio(d, NULL, 0, dest, dest_mode); if ( target != NULL ) { - vmsi_inj_irq(target, vector, trig_mode, delivery_mode); + vmsi_inj_irq(target, vector, trig_mode, delivery_mode, callback, + data); break; } HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "null MSI round robin: vector=%02x\n", @@ -89,8 +88,8 @@ int vmsi_deliver( for_each_vcpu ( d, v ) if ( vlapic_match_dest(vcpu_vlapic(v), NULL, 0, dest, dest_mode) ) - vmsi_inj_irq(vcpu_vlapic(v), vector, - trig_mode, delivery_mode); + vmsi_inj_irq(vcpu_vlapic(v), vector, trig_mode, delivery_mode, + callback, data); break; default: @@ -103,6 +102,13 @@ int vmsi_deliver( return 0; } +int vmsi_deliver(struct domain *d, int vector, uint8_t dest, uint8_t dest_mode, + uint8_t delivery_mode, uint8_t trig_mode) +{ + return vmsi_deliver_callback(d, vector, dest, dest_mode, delivery_mode, + trig_mode, NULL, NULL); +} + void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci) { uint32_t flags = pirq_dpci->gmsi.gflags; @@ -119,7 +125,8 @@ void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *pirq_dpci) ASSERT(pirq_dpci->flags & HVM_IRQ_DPCI_GUEST_MSI); - vmsi_deliver(d, vector, dest, dest_mode, delivery_mode, trig_mode); + vmsi_deliver_callback(d, vector, dest, dest_mode, delivery_mode, trig_mode, + hvm_dpci_msi_eoi, d); } /* Return value, -1 : multi-dests, non-negative value: dest_vcpu_id */ diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c index a9256e7ef51..2331af896d4 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -796,13 +796,9 @@ static int _hvm_dpci_msi_eoi(struct domain *d, return 0; } -void hvm_dpci_msi_eoi(unsigned int vector) +void hvm_dpci_msi_eoi(unsigned int vector, void *data) { - struct domain *d = current->domain; - - if ( !is_iommu_enabled(d) || - (!hvm_domain_irq(d)->dpci && !is_hardware_domain(d)) ) - return; + struct domain *d = data; spin_lock(&d->event_lock); pt_pirq_iterate(d, _hvm_dpci_msi_eoi, (void *)(long)vector); diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 4f294232fb7..9ac3e4f48f6 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -142,7 +142,7 @@ struct hvm_hw_stdvga { void stdvga_init(struct domain *d); void stdvga_deinit(struct domain *d); -extern void hvm_dpci_msi_eoi(unsigned int vector); +void hvm_dpci_msi_eoi(unsigned int vector, void *data); /* Decode a PCI port IO access into a bus/slot/func/reg. */ unsigned int hvm_pci_decode_addr(unsigned int cf8, unsigned int addr, From patchwork Wed Mar 31 10:32:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6AECC433C1 for ; Wed, 31 Mar 2021 10:36:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2BDF461582 for ; Wed, 31 Mar 2021 10:36:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BDF461582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103841.198067 (Exim 4.92) (envelope-from ) id 1lRYCu-0004vo-8D; Wed, 31 Mar 2021 10:36:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103841.198067; Wed, 31 Mar 2021 10:36: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 1lRYCu-0004ve-3y; Wed, 31 Mar 2021 10:36:16 +0000 Received: by outflank-mailman (input) for mailman id 103841; Wed, 31 Mar 2021 10:36:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCs-0004un-Gm for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:14 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 708e5ba8-4afb-4791-94a4-f598a6585d17; Wed, 31 Mar 2021 10:36:13 +0000 (UTC) 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: 708e5ba8-4afb-4791-94a4-f598a6585d17 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186972; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=BZyxwqwyKCBvk+CFEEPMfCfivieAaaU9nS1MxnsMyOk=; b=anUu9mHhbDqO7K2cjT5JUqp7AMREM17mju5grLFBe+qMiuELHJI4JjM/ YlLGo+Kayp+3uExbeVjSuhXLV+2uOdfPjyCxYVPDIpXsYCQ5vAt6XZm/0 4zZs8RkmbQFJbo60xO2exgi0eifEOLBxWFmMrcJxubAs2JEm33OkRp9xd I=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 7sweMx5zWJWaAZNnY8I3TtLQCrhCvt5dyYhSWNsHIcX7mNhRYJVlxKxRgWU3iQD6bGTKdMw74D 7Y2rt241g3zBMKcr45pqAnzpmYPbZO/rN77CWnLE3dXrV2eo6knASSLCNHgfeJNILDYLhKban7 0B3p54OROfNl6fSKuQ89IJnwQLZvJ9BIRckSmJ+iIiM256oMZBRFDDPgEdQI3rfq1l7Stbomas ffpeuIlarle2akh6b2GihexNZ0ybHLjmaj0DfIsBLRIrQYr9wnYo4mD1ySey5FvXIRm4PhXZIa bII= X-SBRS: 5.2 X-MesageID: 40415665 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:EBtb1K3DTN0tXw2AbsaiQAqjBTd3eYIsi2QD101hICF9Wvez0+ izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/FIyKErF/OHUBP9sGWlaLtj44zr3iH6F0TFmtJ1/Z xLN5JzANiYNzVHpO7n/Qi1FMshytGb8KauwdzT1WtpUBsCUcBdxi1SYzzrdnFebg9AGJY/Cd 6g/cJBvTWtYjA6ac68C3kDUYH41qH2vbjhZgMLAANi1RmWgVqTmcPHOjW7/jNbaTNAxr8+7X PI+jaW2oyPu+y2oyWssVP7wI9RnLLau7l+LeyKzvMYMzD9zjuvDb4RIIGqmBAQjKWR5E0xkN /Kyi1QT/hbz3/KZGm6rV/M9mDboU8TwkTvw1OZnnfvyPaRLFlRa7sj9PBkWyDU5EY6sNZ33L gj5RPii7NtAQ7dhyO43tDUVnhR5zuJiEA/mu0ehWE3a/p4VJZtq+UkjSZoOaZFNif75Ic7Kf JpHcHR6d1HGGnqEUzxjy1BxsehUW80GQrDak8eutaN2zwTp3xhyVAErfZv0ksoxdYYcd1p9u 7EOqNnmPVnSdIXV7t0AKMkTdGsAmLAbBrQOAupUBvaPZBCH0iIh4/84b0z6u3vUocP1oEOlJ PIV04dnXIuemr1YPf+nKFjw1ToeiGQTD7twsZR69xSobvnXofmNiWFVRQHj9agmfMCGcfWMs zDea5+MrvGFy/DCIxJ1wrxV915Mn8FSvAYvd49RhagucTOBor2tvHKUfraKbb3eAxUGF/XMz 8mZnzeNc9A5kekVjvTmx7KQU7gfUT54NZRHcHhjq0u4blIErcJnhkeiFy/6M3OAyZFqLYKcE x3J66itqu6oGKx7FvZ9mkBAGsYMm9lpJHbF19arw4DNE35NZwZvc+ERGxU1HybYjhyUt3RCw wag1hs46q4I9ixyEkZepyaG1Pfq0FWiGOBTp8alKHGz9ziYIkEApEvX7E0Mx7KGRxzkQNDs3 xCdwcAe0/aGlrV+OaYpa1RINuaW8h3gQ+tL8IRg2nYr1+gqcYmQWZeYySjSveNgQElRyNdg3 p496N3usvGpR+fbU8ExMgoOlxFb2qaRJZLFh6Maolvlrf3Qw1oVmuRiTuGixY8R3ry+ywp9x /cBBzRXcuOLktWu3he3Kqvyl9ye2mHV29ba3xxs+RGZC/7k0c29dXOSru40mOXZFdH//oUNy vdZyAOZil0wcqs6RKTkDGeNHkvy5k0JNbBBLA7f7y74ALqFKS40YU9W9NE9pdsM97j9tIRWe WEYgmPMXfWDfgq1wH9nAdSBABE7F0f1dXm1x3u4DLmgDoRAf/OLE9nQL9eCdeG9GTgT+uJ1p I8rd9dh5rFDkzBLvq9jYfQZHp/DzmWh0icZeQhs4pVsqI/r6EbJeiSbRL4kFV8mCwjJ8L1nn 4ESKt14Lr9KpZiFvZiDh5xzx4MrpCzN0MlvQz9P/8mcXwsh3HdOcmV47Cgk8tZPmSx4C/5OV yS6ERmjo/4dhrG8b4REKQrJ2tKLGA69XR55euHHregQjmCRqVm/FCgNGW6f6IYYK+ZGa8Iph I/x92TheeYe27Z3w/X1AELb55mwiKCQcmoBhiLFvMN29umOU6Uiq/v2fWNtl7MOHKGQnVdo5 ZEe0wWZtlCjTdnrLRf6FnMdoXH5mQ/k1Vf5jl7kEXKwYbO2haDIX17 X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40415665" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nt3GhNGopzsE2YzTerzZrxwAENTHZOA2BtwDyIC13GHI8g6UneOeJXM83D/uLGATlRC0wJqHXDZWeQIWIL1fLLngqTxWGhephZNQWrcMpdLehv7NDFd+Si4kQJKuAGjN9oS1XRxULMM/nWTnt6eZ7Bgviyxpbk4rq/L8P6+5N9bNWtLpkOvoB3QFwZSoOlfF4K8CcYg6dkOAvsHsFOctDhUMakiHcjV/JYBoMO1goxCuWQl2xP1U5T1A4BhoJMrbzBuvU6lweKXy11m3I++X7s+Kb/bP7eCr4O/twSg2lyDGUQhrX4BJfQm4U3w8sQcKdg9H6wNubDRn0jQ++RBi4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YbLS6BH8MbuCXwxN5xjKUX6UwKmNt7gnMdLP8UFuW2Y=; b=G8Tgtvm72k9EzMB5hH2xb/QvQqmjaG40JxAoQtpeyq6vOjELydrqhjF07xLDLUlVkUWkTJ5uz9UNwhI6FQMGsLGj1x9JDWf6J9n2K/KSFFBZ1CVHfguM450CqmNnxasGh0RtaVwYdswZ88et0g10+D1FnELdPvjZyG3JG+SYMkeCq30vR8slfU+1eTzLrQ6rfudVNQmPy1XjBQ0/LL1trftJrFhcx/PfcQdekz+Tj3ag9xyTYPvp528s0LFeykB0N4OF3ncJNYihDaOipzuP3tzk5NhYR/g5upBO3Od1Jz/y1dmafC/moqyXu/3QYu4GM2a9x5zI9vwLSgnIZJP9yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YbLS6BH8MbuCXwxN5xjKUX6UwKmNt7gnMdLP8UFuW2Y=; b=KEKsVdkyKlVa/Q+s8RzEVvve8vqeAKcPkP8yiGIFTFT6VswAkiX2God7WCHd5S2kQOsBZJrhEnjYNP3+wsctiihkIArWAPRjFel1a9/r4JJ6jwxPOYgQbWY+PVNyu0IjbFcycghLhCa8sW6picM5IGik1ALDVqGYSc7Yi9OheJ8= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 05/11] x86/vioapic: switch to use the EOI callback mechanism Date: Wed, 31 Mar 2021 12:32:57 +0200 Message-ID: <20210331103303.79705-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0163.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::26) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8063ccd-c7ae-4def-a92f-08d8f430c94c X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /FFoXPnFQtGk3HaQwqeNi3TMIhhfxrj3infJ+2yDmaEOrXF+plMov929zYxyWtUU423JsZL8YDUbjMtLrttS1ikOYJUSQX9CufkYu1wfD482gIdOxm+k9sGZswZ6dClfl6+Cdy78GLyLEivg3vbhSwgUd2wt4RLuMyBwxnRVuvpc1ZGDWscWrqEjyzEsuoBdBqGJbbm1tiHEJi/rXPJ6F6s2SW3IaAqAD4dvwr4LCPLqjfXrkcAlM2ez70AZubdumVqGF9AGj7CSuPyDPRovTV4hn87Dg1hrzXj/xVHQ7j/17HPyYh1kPu6tD8GtpaaCUPmTas22LqGh80NamRVxCD3l6yKqHnPSoU9xbUCyDpY7ug8TGpUiTlStIAQsATXCC0VGIBTh2cwmkhmVi9ulMOxJR/uSkIUfV/HZZ6glbqq37A2ym5iUhuaniMsnMAsAza/mGABs873wJCnAbn2xaAPqfLNshRNUQn6Tu3E60RkmNFoYwGS/i0VxboH/B1lVXbi9+nQKx8xL2VYxv/yFIGUdZJb9zTzwRCvsiakYmfKb27LYx5esXShzRIqZ4CJQSw2UUZqRU5lg3hCnQYMnd/46RCGivqS+0enOkO5Mq+pC0tVtts5uMQaVYVS3WsFWqiEu66jHoMRE5p0dIKsm4dl5qq4sqwno8NEsOFz4yx6YH5a7kGc60TQpjY9hPIeH X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?DZGvpClnu02zLEkJP7u9mmmCx1QuNj?= =?utf-8?q?QlYdWQ0LU9WYXDxxsBUlD1rgMzJTQxv9t0UYa8Yzyuv4NH6kxjc6aZ3mFc9DOB3nW?= =?utf-8?q?V+FqViO5xtSjzIpaFrxuJ7Wiuwvp3vNivG39n0evD97iW/eJ7sMdO4DvKj9fRa6Hl?= =?utf-8?q?ZvOrOteR5wbyys6XfVFdfaZ+ljQvdJEoC9NSOPWIlI1ICHZH4JYHV3Ir88GFsGQUY?= =?utf-8?q?Fsyxg4L5dItzhenLfPt0IpB5Os76Mw6QokYIoqkviw485FOW5SXkEaYgQ9ppLaSUu?= =?utf-8?q?BGCWiBmZLFRXcnVQ8xb30bcCUt//t8lTCzcI8+tTyBBO9V2l256T4MF6/VpEb4jN+?= =?utf-8?q?QpqAbTaXvFpKyYFqgGCOHPaXColDBf7Yg4327sVjZBcarsjBBLxiuG0Jw3uRF106a?= =?utf-8?q?4GYxboqRFlJtiFc45cwgqmaLCF+Qk1D1Yh7tTr+6DbTXT4ug8rVvFPF23ih7A488k?= =?utf-8?q?wkMco910So+tRDjlB4CvPLcIcSsUdotT9yFP7u4AusfCp/xG4CLW8LXA2wkDL7PS9?= =?utf-8?q?S6aqIEKDEQ5V3t4vn3R6ZtvfimGOm77Q9o4MePsPRjLyQd74jL99tDb/yJwIniPZS?= =?utf-8?q?BkW7r160S5Ida/qgT5bYRKWvPEYcV8CCz7DLGkUFvFeQs8Hnzxxb2UqMD9zLDkugG?= =?utf-8?q?Wlomnk6sMBm/ToDxGsHtWTupfiEiKDiaoVwz535e+hbSSR4rjeuEcd2TUNQ93E33i?= =?utf-8?q?CSOGBhf2SbFyHGxJusOmGsbAYM2dG5fn5iVCojYThGwvMSfC39BVfgkn8Q/cE+gKr?= =?utf-8?q?izXlfiW9rj6nfpbGRrazvEDBFFhWiFj8qD4EhtNQpjvVexvs2UzPC2mEpl/qgT90Y?= =?utf-8?q?SsLWEucSJrLqW0ejn1RUzOdQ3645+m/N6x7gXw91zK7SZ6m9/Eu68l+afwUfqZtew?= =?utf-8?q?CcASLQlpHdFspz8hEU2GUHIqCUSKN2OY6oIhvQWIg1H9kkuB5i/kEMceh+7b86so7?= =?utf-8?q?OGwCLCy0y/uKMaSiE5kJdykUOjfKGeR6Hr558vop2CwiYJWOytVJOiCf0PM+j0QMh?= =?utf-8?q?dPcKPeRWjmjNioq1bc1rgxH+Ry4J+5c1/C84yySWl2GWzlWhMpEqQUqSDThvEREbH?= =?utf-8?q?mNznvbGsRXSX86xC5ZQ6Qh3IK89Db8P+R+LI7+qBqmunXDrDGAVDAUarc505ji6V8?= =?utf-8?q?21IR2eut6nO/8HCTaRLwxZk6zkf7D3+AvF0jHDAaCgzEBCXyp/jo01Uq+fQf1Q36j?= =?utf-8?q?V/lwDYeR/TP02/FOLVmomnqqzDLY+Uwh8iEmJKYMfBrFuB/atB95mQZWMzdx+OtJ9?= =?utf-8?q?SQEyWerXsdy3rZ?= X-MS-Exchange-CrossTenant-Network-Message-Id: a8063ccd-c7ae-4def-a92f-08d8f430c94c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:04.6593 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bWaxEIV5pDDpgahkbuy9zCxae3GNfBE9cDuQjcyBJeNdzTb9Nx53g8mynf5xb8FaYUIvreKXi3l80ZddvRAKPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Switch the emulated IO-APIC code to use the local APIC EOI callback mechanism. This allows to remove the last hardcoded callback from vlapic_handle_EOI. Removing the hardcoded vIO-APIC callback also allows to getting rid of setting the EOI exit bitmap based on the triggering mode, as now all users that require an EOI action use the newly introduced callback mechanism. Move and rename the vioapic_update_EOI now that it can be made static. Signed-off-by: Roger Pau Monné --- Changes since v2: - Explicitly convert the last alternative_vcall parameter to a boolean in vlapic_set_irq_callback. Changes since v1: - Remove the triggering check in the update_eoi_exit_bitmap call. - Register the vlapic callbacks when loading the vIO-APIC state. - Reduce scope of ent. --- xen/arch/x86/hvm/vioapic.c | 131 ++++++++++++++++++++++++------------- xen/arch/x86/hvm/vlapic.c | 11 ++-- 2 files changed, 92 insertions(+), 50 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index dcc2de76489..d29b6bfdb7d 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -394,6 +394,50 @@ static const struct hvm_mmio_ops vioapic_mmio_ops = { .write = vioapic_write }; +static void eoi_callback(unsigned int vector, void *data) +{ + struct domain *d = current->domain; + struct hvm_irq *hvm_irq = hvm_domain_irq(d); + unsigned int i; + + ASSERT(has_vioapic(d)); + + spin_lock(&d->arch.hvm.irq_lock); + + for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) + { + struct hvm_vioapic *vioapic = domain_vioapic(d, i); + unsigned int pin; + + for ( pin = 0; pin < vioapic->nr_pins; pin++ ) + { + union vioapic_redir_entry *ent = &vioapic->redirtbl[pin]; + + if ( ent->fields.vector != vector ) + continue; + + ent->fields.remote_irr = 0; + + if ( is_iommu_enabled(d) ) + { + spin_unlock(&d->arch.hvm.irq_lock); + hvm_dpci_eoi(vioapic->base_gsi + pin); + spin_lock(&d->arch.hvm.irq_lock); + } + + if ( (ent->fields.trig_mode == VIOAPIC_LEVEL_TRIG) && + !ent->fields.mask && !ent->fields.remote_irr && + hvm_irq->gsi_assert_count[vioapic->base_gsi + pin] ) + { + ent->fields.remote_irr = 1; + vioapic_deliver(vioapic, pin); + } + } + } + + spin_unlock(&d->arch.hvm.irq_lock); +} + static void ioapic_inj_irq( struct hvm_vioapic *vioapic, struct vlapic *target, @@ -407,7 +451,8 @@ static void ioapic_inj_irq( ASSERT((delivery_mode == dest_Fixed) || (delivery_mode == dest_LowestPrio)); - vlapic_set_irq(target, vector, trig_mode); + vlapic_set_irq_callback(target, vector, trig_mode, + trig_mode ? eoi_callback : NULL, NULL); } static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) @@ -514,50 +559,6 @@ void vioapic_irq_positive_edge(struct domain *d, unsigned int irq) } } -void vioapic_update_EOI(unsigned int vector) -{ - struct domain *d = current->domain; - struct hvm_irq *hvm_irq = hvm_domain_irq(d); - union vioapic_redir_entry *ent; - unsigned int i; - - ASSERT(has_vioapic(d)); - - spin_lock(&d->arch.hvm.irq_lock); - - for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) - { - struct hvm_vioapic *vioapic = domain_vioapic(d, i); - unsigned int pin; - - for ( pin = 0; pin < vioapic->nr_pins; pin++ ) - { - ent = &vioapic->redirtbl[pin]; - if ( ent->fields.vector != vector ) - continue; - - ent->fields.remote_irr = 0; - - if ( is_iommu_enabled(d) ) - { - spin_unlock(&d->arch.hvm.irq_lock); - hvm_dpci_eoi(vioapic->base_gsi + pin); - spin_lock(&d->arch.hvm.irq_lock); - } - - if ( (ent->fields.trig_mode == VIOAPIC_LEVEL_TRIG) && - !ent->fields.mask && !ent->fields.remote_irr && - hvm_irq->gsi_assert_count[vioapic->base_gsi + pin] ) - { - ent->fields.remote_irr = 1; - vioapic_deliver(vioapic, pin); - } - } - } - - spin_unlock(&d->arch.hvm.irq_lock); -} - int vioapic_get_mask(const struct domain *d, unsigned int gsi) { unsigned int pin = 0; /* See gsi_vioapic */ @@ -611,6 +612,8 @@ static int ioapic_save(struct vcpu *v, hvm_domain_context_t *h) static int ioapic_load(struct domain *d, hvm_domain_context_t *h) { struct hvm_vioapic *s; + unsigned int i; + int rc; if ( !has_vioapic(d) ) return -ENODEV; @@ -621,7 +624,43 @@ static int ioapic_load(struct domain *d, hvm_domain_context_t *h) d->arch.hvm.nr_vioapics != 1 ) return -EOPNOTSUPP; - return hvm_load_entry(IOAPIC, h, &s->domU); + rc = hvm_load_entry(IOAPIC, h, &s->domU); + if ( rc ) + return rc; + + for ( i = 0; i < ARRAY_SIZE(s->domU.redirtbl); i++ ) + { + const union vioapic_redir_entry *ent = &s->domU.redirtbl[i]; + unsigned int vector = ent->fields.vector; + unsigned int delivery_mode = ent->fields.delivery_mode; + struct vcpu *v; + + /* + * Add a callback for each possible vector injected by a redirection + * entry. + */ + if ( vector < 16 || !ent->fields.remote_irr || + (delivery_mode != dest_LowestPrio && delivery_mode != dest_Fixed) ) + continue; + + for_each_vcpu ( d, v ) + { + struct vlapic *vlapic = vcpu_vlapic(v); + + /* + * NB: if the vlapic registers were restored before the vio-apic + * ones we could test whether the vector is set in the vlapic IRR + * or ISR registers before unconditionally setting the callback. + * This is harmless as eoi_callback is capable of dealing with + * spurious callbacks. + */ + if ( vlapic_match_dest(vlapic, NULL, 0, ent->fields.dest_id, + ent->fields.dest_mode) ) + vlapic_set_callback(vlapic, vector, eoi_callback, NULL); + } + } + + return 0; } HVM_REGISTER_SAVE_RESTORE(IOAPIC, ioapic_save, ioapic_load, 1, HVMSR_PER_DOM); diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 10b216345a7..63fa3780767 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -192,7 +192,13 @@ void vlapic_set_irq_callback(struct vlapic *vlapic, uint8_t vec, uint8_t trig, if ( hvm_funcs.update_eoi_exit_bitmap ) alternative_vcall(hvm_funcs.update_eoi_exit_bitmap, target, vec, - trig || callback); + /* + * NB: need to explicitly convert to boolean to avoid + * truncation wrongly result in false begin reported + * for example when the pointer sits on a page + * boundary. + */ + !!callback); if ( hvm_funcs.deliver_posted_intr ) alternative_vcall(hvm_funcs.deliver_posted_intr, target, vec); @@ -496,9 +502,6 @@ void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector) unsigned long flags; unsigned int index = vector - 16; - if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) ) - vioapic_update_EOI(vector); - spin_lock_irqsave(&vlapic->callback_lock, flags); callback = vlapic->callbacks[index].callback; vlapic->callbacks[index].callback = NULL; From patchwork Wed Mar 31 10:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B532DC433DB for ; Wed, 31 Mar 2021 10:36:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4E4BB61582 for ; Wed, 31 Mar 2021 10:36:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E4BB61582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103842.198079 (Exim 4.92) (envelope-from ) id 1lRYCw-0004yi-Id; Wed, 31 Mar 2021 10:36:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103842.198079; Wed, 31 Mar 2021 10:36: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 1lRYCw-0004yV-EX; Wed, 31 Mar 2021 10:36:18 +0000 Received: by outflank-mailman (input) for mailman id 103842; Wed, 31 Mar 2021 10:36:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYCu-0004un-Jc for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:16 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d4ff5b2-d862-48a5-b582-cb48b6cd8810; Wed, 31 Mar 2021 10:36:14 +0000 (UTC) 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: 0d4ff5b2-d862-48a5-b582-cb48b6cd8810 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186974; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Y/QS2yMljZx17JZ183drY6zkAree+xKrpiH8jux6JWw=; b=frG6LJDBgyiknhOAFavKyQNVbCg4SzbvVd7Db3SMNzAsJf41s5tdWzm1 6ePPHcREa6ltcdlSd5wjWiiH1QvWVrgEVJ27BQyxwvowzvd8xH9tA6u59 c9AXv05tb+ypfSyvyY/XdbIWdBEIptOPprQdQE7PFlie/C8z6hMJ7T/UF U=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: wWmy6Mt5kFaKYZEc499ziIdusaUiSobP3sHa3PeByLPZx7RFckDtP7NUK6rsB5rR5Z01MDGYQn gDQlTMyVMP69+9Mfr0zoBq74ygorLD6xSzW/9ZbMiGDr+OkLTmpxhrj+jw/Y6uQAzeR6dZLfbT vbXmXKBCoz2bxbMvqH/DnG92SvXZZMKkaWQWL274dsQCPjy/SMC121m244ebIGsRI/qzIFamTS J59KP3hZzZy6dt3Dzgai2iiqY5aw8tFiXwRH2HdCDDnPqLzpACyPkFnfKNbh9JWH9DHkAIEcA1 B8A= X-SBRS: 5.2 X-MesageID: 40688166 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:s/AwqaMhpKSL4sBcTxv155DYdL4zR+YMi2QD/1xtSBBTb8yTn9 2vmvNe7hPvlDMNQhgb9OyoEq+GXH/a6NpJ8ZAcVI3SOTXOlUmJCMVZ7YXkyyD9ACGWzIRg/I ppbqQWMrLNJHdgi8KS2meFOvIB5PXCz6yyn+fZyB5WPGNXQoVt9R1wBAreMmAefml7LKE0Hp ad+cZLzgDIERgqR/+2G2UfWKz7r8DL/aiMXTc9GxUl5AOS5AnYi4LSLh7w5HYjegIK+5gO2y zvkwv15qKs2svLsCP05ivowLl93PfkwttHLsSQhsYSMSWEsHfUWK1RH4eskRpwjOaz6Es7sN SkmWZdA+1Dr0n/U0vwgRzx1xLu2DwjgkWStmOwsD/YjuHSABcZYvAx4b5xQ1/ixGcL+OxY6u Zt2VmUspJGZCmw5BjV1pzzeDxB0navrWFKq591s1VvFbEwRZV2toIl8EZcAP47bVnHwbFiKu VoAc3GjcwmF2+yXjTctmlr9tSmQm4+KBeAWlQDocyYyVFt7QlE83c= X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40688166" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WlGG0Y9eRKNseB7+FnHBhySa15xNxP1ETh0dmMygh9ngtLp5nSKdmj7aykCBQbMdgfQI/ziNLQdjo3ALGF2VpvGF5p1zvEivl+1XBGAGnY7UZhY/LfG6N2O5Tr3wBDNtXttN8WjW0MbcXgpPzLStP5gxYQEEJpXnVh44cZrT3lyFrr/YmHmBQxl4uCZkpDSaCvnu2rLxqkMsZSTOMKHyT2Z54b710Cf9fnKZCDUbcyOA2iDjP3pKK2D+eSzPYjn/MreAT4TnbFZSp4rXklqljHehIVClO15YjorL7ULHnxW7ppXYPOQw5kIyIz375u6bmT5lYBmiLlXV80Y8zzX63A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E6xRU0mfdtEd9NzCqYmTFj08AUSTIGMnJkukMnC1rB0=; b=h40QaFppjkYOH9/yXCkyL04aJz/Vc+a8fvLYNJxS0AROE0Y48opzIKeNE1P2pOeM7EqhUF/hsNi56KLZZB1l21RDYtQrKtVinY4drGq0u1GFOsD5wynFAeb7b4u4dWYieW63X5SNdwuPiPQBoDD7z7cPmT8aL50wDyHIhVa+4JdeDhdl3o3cJZGEE8qriLfyA7CWsrkQcdThyHXqvW67H/3rQkNqYrQOT6rqodhFvQvrryHI1OAQNAk5u5vy00kp4UZpE0r99DdXddnvr8D54OzsFtf2EmkhxSjmz7KCNSwekV7fJEMKcRBYrhIJaCF3Lz7QtQWVidzlEKaY1HsAdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E6xRU0mfdtEd9NzCqYmTFj08AUSTIGMnJkukMnC1rB0=; b=eSKxUZIS2qix+6UTgILv27HcsYKC0RwN7Zs0VMjBKp15yGVcusXYO+1fWO/kI2DNkxR47JXl9GtanWeCfPfvux7M7HE1A4Mdf3Takd3BjZ3Gto1jvw73/XKO4WF6PYINj2HovNmQm4l+IWcA/4ctSeH+J5PlJQX4HMLUM1c+oKM= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 06/11] x86/hvm: allowing registering EOI callbacks for GSIs Date: Wed, 31 Mar 2021 12:32:58 +0200 Message-ID: <20210331103303.79705-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0102.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::18) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f54b22c-0caf-468c-47da-08d8f430cd47 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qV69vlMrlqyZ5belblE9aRTkOBzKR54r4QshrMwQWAeb2G4R638+S7LgF3CJAacPm7363t9nwMXV+kmwsKPYUcDwYhcspGqllPHB2xnYDfnJJX45e8YDQnE3+tuoLhDZDmENUjGYitaK+IdM2K65P02P4xQgRavU5UedA6jfFgzm+s8Cp0HpgNI+HSBt2gW+80lLHe/FzZcKy/kFDdz0IaxJmlPGtbU5lqXlArMNjUTnVm/IIhzj8xXgtymgJFO3PLrle/wKe/oH07knbTlnEFmuRNdB6+++3FD7wIgcS+vgtlLNZkCsXnyTzIFoQvmr515j1t8YuRSlAMnRQxsE5IjjlyooBl9OslXkIsGz0akvPEBk7P0IWwpRK/gWWNtg0sx/n2OVJsFdPYfXbZUTlkzv3nbp/nQfxPG7nEt314rvCzBcN3GPzVFZFyB8GZnwnMf9jqbYV2XqkPGOQB91Lk3kTc2JX02FC5AVwDwgyWokymRBld7x1jOeWq4yKRDZi0e4jC9mtjEbP839NBMXqYBsxluknwOgLGAlHHQ/eHh35+iquYq3wUT8EXYVVdB4lmBex73pvS7v9wylGlqKVnOIs70NFViv2pUHSyFoDr38D9FwLbNExjyuMjLIzZ7K9EggGhDX9Cc5yudQGycwqbI8klMMtlJY9eR4E6GNC1M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(30864003)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?E6ndYLsDmQgoF0nmu7lg9WGdRUUa9Z?= =?utf-8?q?E0TD7OdhgblmoZ/bTZHCYx1gwePQbAqqKtjLq0n2pS1oW1tdKlUAGStxurIBPj/wK?= =?utf-8?q?SGnft6BdBJtnDv61UB9DBF8h1Vc3qaPv0uvUoxKWtxNg5qkiEDc98T5OgEZCPABUL?= =?utf-8?q?Z1aOhDLe7/q9x6Bafd/l7KSfVN3uQuKzU4xPLR0ISYqfFQvseiUZ9ADDmVRQResE8?= =?utf-8?q?96i5BpAugA6ywbSwueubHnPrfjw8d68+GKAl6KxySxF/0CHpP2yJp1irxJX1TOZu3?= =?utf-8?q?bdxoG6wuSttP5YjCkkmZ1tuEOB/T/ccQKgxORbCVCiFJN6pySY/xDi3dIYNXa7YIj?= =?utf-8?q?G9OxM5ao04GOAk6vBOXoW+qjcEVKAmeUQ3c1jIDifbG3xwVFblJmVCtQiJMpEastS?= =?utf-8?q?0hAf+LlK+8J8RxhuJrGmeXMBST6SfTSEyvPeClopUjXJZHZ9KRciPL8/+icWAeWUD?= =?utf-8?q?hVZqvxy8IWzGyr+6uiJ13dR6+IUOeuebOgW4rcd9NHl94TE84tdFeh9yNWEVQzOcA?= =?utf-8?q?bNwhQafgBbrcBLPDyj8UUDKcizAkKxvL/aXfC5/SvrbLacqeAGGtFXZ2T3pUKDaYw?= =?utf-8?q?S0+udFaBCxBESGev/JCRGdKCy3mJFJpQNbUZTTXUG9YYNgMf2A+NKZ1BEwlfYAhz2?= =?utf-8?q?S3+X38aLDyqdqsz3NiH1bLBS2DE9GhfmQL7hlHy/SUwGBTONcFu32pAmPVEgwv0j8?= =?utf-8?q?sZ3ONBC2TPADa6wMj2lUU+Subzw3A5aNMe8T6Olt74DVbEtZMalIqv9MZ7xK45OY4?= =?utf-8?q?R9J7cGGeYDFDRD6oXUYv/j6huot3zOfXSTyd+0iWe0iWriEdKMGb9rya8TwURqjEG?= =?utf-8?q?AJ2SkZ5Pk8XSrqBphoheLkoC0XzakqEJV72BKJjr4NuAk6pJtjtLVy+HLrDYhi0W6?= =?utf-8?q?imq9QUw91cbjRqB/LYj3EbsXA6ZroYPn0QFPka9ROlLZegtD9+hWtyGeSiF7suyt7?= =?utf-8?q?39uphyfGudE/U0YzA1K1vRDLdue5teVPcDkpN/nijsxvwzg71ig2/L/1MZkSocL0k?= =?utf-8?q?LNhv08SEEu8zjXuoJQ1vL9ov68yks+VNcgZiZQn+q89r+fdtJ0UWuc3K+FhgwHroD?= =?utf-8?q?cpGzfSmUeTXXgKNd+IyE63kl8b5MGUVynBm3Tq8pK79wACXrzwQ/68YoIqZNsPZUq?= =?utf-8?q?3QtzoUVWsEJRJB8vbTALCbIP8NBzVwSdHEiKtCZDynJJFOYdDLvPcGoeHI6nIdFrN?= =?utf-8?q?oUYt+GOiP1Th0D5azGXPO3PHengI+ZOCJKbSHqgfP7FstRd3Ho00txK3cYkfJMFr1?= =?utf-8?q?zbBPN4FAl6GSf5?= X-MS-Exchange-CrossTenant-Network-Message-Id: 1f54b22c-0caf-468c-47da-08d8f430cd47 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:11.3399 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bzdZ8MiIPU753/8ugFMbGJJ/81w6i/f97lWoooA+4q4+OFsADL4AQZp523tqyFxZOLqNkHzAuzfVWnZ9HckujA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Such callbacks will be executed once a EOI is performed by the guest, regardless of whether the interrupts are injected from the vIO-APIC or the vPIC, as ISA IRQs are translated to GSIs and then the corresponding callback is executed at EOI. The vIO-APIC infrastructure for handling EOIs is build on top of the existing vlapic EOI callback functionality, while the vPIC one is handled when writing to the vPIC EOI register. Note that such callbacks need to be registered and de-registered, and that a single GSI can have multiple callbacks associated. That's because GSIs can be level triggered and shared, as that's the case with legacy PCI interrupts shared between several devices. Strictly speaking this is a non-functional change, since there are no users of this new interface introduced by this change. Signed-off-by: Roger Pau Monné --- Changes since v2: - Latch hvm_domain_irq in some functions. - Make domain parameter of hvm_gsi_has_callbacks const. - Add comment about dropping the lock around the hvm_gsi_execute_callbacks call. - Drop change to ioapic_load. Changes since v1: - New in this version. --- xen/arch/x86/hvm/hvm.c | 15 ++++++++- xen/arch/x86/hvm/irq.c | 63 +++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/vioapic.c | 29 ++++++++++++---- xen/arch/x86/hvm/vpic.c | 5 +++ xen/include/asm-x86/hvm/irq.h | 20 +++++++++++ 5 files changed, 125 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index e7bcffebc49..0279014e66e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -608,7 +608,7 @@ static int hvm_print_line( int hvm_domain_initialise(struct domain *d) { - unsigned int nr_gsis; + unsigned int nr_gsis, i; int rc; if ( !hvm_enabled ) @@ -655,6 +655,14 @@ int hvm_domain_initialise(struct domain *d) BUILD_BUG_ON(NR_HVM_DOMU_IRQS < NR_ISAIRQS); ASSERT(hvm_domain_irq(d)->nr_gsis >= NR_ISAIRQS); + /* Initialize the EOI callback list. */ + hvm_domain_irq(d)->gsi_callbacks = xmalloc_array(struct list_head, nr_gsis); + if ( !hvm_domain_irq(d)->gsi_callbacks ) + goto fail1; + rwlock_init(&hvm_domain_irq(d)->gsi_callbacks_lock); + for ( i = 0; i < nr_gsis; i++ ) + INIT_LIST_HEAD(&hvm_domain_irq(d)->gsi_callbacks[i]); + /* need link to containing domain */ d->arch.hvm.pl_time->domain = d; @@ -714,6 +722,8 @@ int hvm_domain_initialise(struct domain *d) fail1: if ( is_hardware_domain(d) ) xfree(d->arch.hvm.io_bitmap); + if ( hvm_domain_irq(d) ) + XFREE(hvm_domain_irq(d)->gsi_callbacks); XFREE(d->arch.hvm.params); XFREE(d->arch.hvm.irq); fail0: @@ -776,6 +786,9 @@ void hvm_domain_destroy(struct domain *d) vioapic_deinit(d); XFREE(d->arch.hvm.pl_time); + + if ( hvm_domain_irq(d) ) + XFREE(hvm_domain_irq(d)->gsi_callbacks); XFREE(d->arch.hvm.irq); list_for_each_safe ( ioport_list, tmp, &d->arch.hvm.g2m_ioport_list ) diff --git a/xen/arch/x86/hvm/irq.c b/xen/arch/x86/hvm/irq.c index 38ac5fb6c7c..b9fa8409b9e 100644 --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -595,6 +595,69 @@ int hvm_local_events_need_delivery(struct vcpu *v) return !hvm_interrupt_blocked(v, intack); } +int hvm_gsi_register_callback(struct domain *d, unsigned int gsi, + struct hvm_gsi_eoi_callback *cb) +{ + struct hvm_irq *hvm_irq = hvm_domain_irq(d); + + if ( gsi >= hvm_irq->nr_gsis ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + write_lock(&hvm_irq->gsi_callbacks_lock); + list_add(&cb->list, &hvm_irq->gsi_callbacks[gsi]); + write_unlock(&hvm_irq->gsi_callbacks_lock); + + return 0; +} + +void hvm_gsi_unregister_callback(struct domain *d, unsigned int gsi, + struct hvm_gsi_eoi_callback *cb) +{ + struct hvm_irq *hvm_irq = hvm_domain_irq(d); + const struct list_head *tmp; + + if ( gsi >= hvm_irq->nr_gsis ) + { + ASSERT_UNREACHABLE(); + return; + } + + write_lock(&hvm_irq->gsi_callbacks_lock); + list_for_each ( tmp, &hvm_irq->gsi_callbacks[gsi] ) + if ( tmp == &cb->list ) + { + list_del(&cb->list); + break; + } + write_unlock(&hvm_irq->gsi_callbacks_lock); +} + +void hvm_gsi_execute_callbacks(unsigned int gsi) +{ + struct hvm_irq *hvm_irq = hvm_domain_irq(current->domain); + struct hvm_gsi_eoi_callback *cb; + + read_lock(&hvm_irq->gsi_callbacks_lock); + list_for_each_entry ( cb, &hvm_irq->gsi_callbacks[gsi], list ) + cb->callback(gsi, cb->data); + read_unlock(&hvm_irq->gsi_callbacks_lock); +} + +bool hvm_gsi_has_callbacks(const struct domain *d, unsigned int gsi) +{ + struct hvm_irq *hvm_irq = hvm_domain_irq(d); + bool has_callbacks; + + read_lock(&hvm_irq->gsi_callbacks_lock); + has_callbacks = !list_empty(&hvm_irq->gsi_callbacks[gsi]); + read_unlock(&hvm_irq->gsi_callbacks_lock); + + return has_callbacks; +} + static void irq_dump(struct domain *d) { struct hvm_irq *hvm_irq = hvm_domain_irq(d); diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index d29b6bfdb7d..099c29466ba 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -285,6 +285,7 @@ static void vioapic_write_redirent( ASSERT(prev_level); ASSERT(!top_word); hvm_dpci_eoi(gsi); + hvm_gsi_execute_callbacks(gsi); } if ( is_hardware_domain(d) && unmasked ) @@ -412,6 +413,7 @@ static void eoi_callback(unsigned int vector, void *data) for ( pin = 0; pin < vioapic->nr_pins; pin++ ) { union vioapic_redir_entry *ent = &vioapic->redirtbl[pin]; + unsigned int gsi = vioapic->base_gsi + pin; if ( ent->fields.vector != vector ) continue; @@ -421,13 +423,25 @@ static void eoi_callback(unsigned int vector, void *data) if ( is_iommu_enabled(d) ) { spin_unlock(&d->arch.hvm.irq_lock); - hvm_dpci_eoi(vioapic->base_gsi + pin); + hvm_dpci_eoi(gsi); spin_lock(&d->arch.hvm.irq_lock); } + /* + * Callbacks don't expect to be executed with any lock held, so + * drop the lock that protects the vIO-APIC fields from changing. + * + * Note that the redirection entry itself cannot go away, so upon + * retaking the lock we only need to avoid making assumptions on + * redirection entry field values (ie: recheck the IRR field). + */ + spin_unlock(&d->arch.hvm.irq_lock); + hvm_gsi_execute_callbacks(gsi); + spin_lock(&d->arch.hvm.irq_lock); + if ( (ent->fields.trig_mode == VIOAPIC_LEVEL_TRIG) && !ent->fields.mask && !ent->fields.remote_irr && - hvm_irq->gsi_assert_count[vioapic->base_gsi + pin] ) + hvm_irq->gsi_assert_count[gsi] ) { ent->fields.remote_irr = 1; vioapic_deliver(vioapic, pin); @@ -443,7 +457,8 @@ static void ioapic_inj_irq( struct vlapic *target, uint8_t vector, uint8_t trig_mode, - uint8_t delivery_mode) + uint8_t delivery_mode, + bool callback) { HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "irq %d trig %d deliv %d", vector, trig_mode, delivery_mode); @@ -452,7 +467,7 @@ static void ioapic_inj_irq( (delivery_mode == dest_LowestPrio)); vlapic_set_irq_callback(target, vector, trig_mode, - trig_mode ? eoi_callback : NULL, NULL); + callback ? eoi_callback : NULL, NULL); } static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) @@ -466,6 +481,7 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) struct vlapic *target; struct vcpu *v; unsigned int irq = vioapic->base_gsi + pin; + bool callback = trig_mode || hvm_gsi_has_callbacks(d, irq); ASSERT(spin_is_locked(&d->arch.hvm.irq_lock)); @@ -492,7 +508,8 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) target = vlapic_lowest_prio(d, NULL, 0, dest, dest_mode); if ( target != NULL ) { - ioapic_inj_irq(vioapic, target, vector, trig_mode, delivery_mode); + ioapic_inj_irq(vioapic, target, vector, trig_mode, delivery_mode, + callback); } else { @@ -507,7 +524,7 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin) for_each_vcpu ( d, v ) if ( vlapic_match_dest(vcpu_vlapic(v), NULL, 0, dest, dest_mode) ) ioapic_inj_irq(vioapic, vcpu_vlapic(v), vector, trig_mode, - delivery_mode); + delivery_mode, callback); break; case dest_NMI: diff --git a/xen/arch/x86/hvm/vpic.c b/xen/arch/x86/hvm/vpic.c index a69aecad912..ca484c31b6a 100644 --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -235,6 +235,8 @@ static void vpic_ioport_write( unsigned int pin = __scanbit(pending, 8); ASSERT(pin < 8); + hvm_gsi_execute_callbacks( + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); __clear_bit(pin, &pending); } @@ -284,8 +286,11 @@ static void vpic_ioport_write( /* Release lock and EOI the physical interrupt (if any). */ vpic_update_int_output(vpic); vpic_unlock(vpic); + hvm_gsi_execute_callbacks( + hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); return; /* bail immediately */ + case 6: /* Set Priority */ vpic->priority_add = (val + 1) & 7; break; diff --git a/xen/include/asm-x86/hvm/irq.h b/xen/include/asm-x86/hvm/irq.h index 07b1ab99cd1..0828c01dd18 100644 --- a/xen/include/asm-x86/hvm/irq.h +++ b/xen/include/asm-x86/hvm/irq.h @@ -21,6 +21,7 @@ #ifndef __ASM_X86_HVM_IRQ_H__ #define __ASM_X86_HVM_IRQ_H__ +#include #include #include @@ -79,6 +80,10 @@ struct hvm_irq { struct hvm_irq_dpci *dpci; + /* List of callbacks for GSI EOI events. Protected by irq_lock. */ + struct list_head *gsi_callbacks; + rwlock_t gsi_callbacks_lock; + /* * Number of wires asserting each GSI. * @@ -138,6 +143,13 @@ struct hvm_gmsi_info { bool posted; /* directly deliver to guest via VT-d PI? */ }; +typedef void hvm_gsi_eoi_callback_t(unsigned int gsi, void *data); +struct hvm_gsi_eoi_callback { + hvm_gsi_eoi_callback_t *callback; + void *data; + struct list_head list; +}; + struct hvm_girq_dpci_mapping { struct list_head list; uint8_t bus; @@ -225,4 +237,12 @@ void hvm_set_callback_via(struct domain *d, uint64_t via); struct pirq; bool hvm_domain_use_pirq(const struct domain *, const struct pirq *); +int hvm_gsi_register_callback(struct domain *d, unsigned int gsi, + struct hvm_gsi_eoi_callback *cb); +void hvm_gsi_unregister_callback(struct domain *d, unsigned int gsi, + struct hvm_gsi_eoi_callback *cb); +/* data is an opaque blob to pass to the callback if it has no private data. */ +void hvm_gsi_execute_callbacks(unsigned int gsi); +bool hvm_gsi_has_callbacks(const struct domain *d, unsigned int gsi); + #endif /* __ASM_X86_HVM_IRQ_H__ */ From patchwork Wed Mar 31 10:32:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A849C433C1 for ; Wed, 31 Mar 2021 10:36:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F3A0F60C3D for ; Wed, 31 Mar 2021 10:36:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3A0F60C3D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103852.198091 (Exim 4.92) (envelope-from ) id 1lRYD9-00059Q-6P; Wed, 31 Mar 2021 10:36:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103852.198091; Wed, 31 Mar 2021 10:36:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYD9-00059H-35; Wed, 31 Mar 2021 10:36:31 +0000 Received: by outflank-mailman (input) for mailman id 103852; Wed, 31 Mar 2021 10:36:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYD7-0004un-G9 for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:29 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4ebcf666-c292-4331-921a-0c4d40323d28; Wed, 31 Mar 2021 10:36:21 +0000 (UTC) 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: 4ebcf666-c292-4331-921a-0c4d40323d28 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186980; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=G6eLB2/DpmPMrCYF/OQauXM9+ZdnMyF85mx9b/zikNE=; b=Gk6GOavTncp8Q66d8nLbHVDTxWR8uAQaBksnFFUqhnYOpjg/6LeSQ2+6 ozCDHdc8shkOkR+oAFx5r87B49Mk/vaY6Wyw1J71xrCpssTGB67Rmrl6U Al33v4pEadg/1LT9bNgx0vaNjsDPzSnRVmixDpWJx/6fs71kO7/yUhUYr M=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: WyPNu5IIhJ6yPNAk93xEijNLhrSkvJsFi68KvRM7XH5BvO/FoNqLy88K0wesJMofLw+OwMWiv0 fqQ2j+5QKHI0J28RD1mXb2u+wvB9ho+DRvMgSbXHpqO/D3M77KEvDV+15TvAAktxIeM+9G522y x2RmiKswoH+DPdFLSW82EtWrE4xNIiFQFmPPFV8ZEK8Jf2YvwJVZvbcDgP1hHni4eyEPDO0Cx2 zuB+R6bYEKdAy46HyZwx/ZS74YR9t5W1T31VWUAHFhnTXbU19rMdAufMn1D1zryctxr+0gSBY6 Izo= X-SBRS: 5.2 X-MesageID: 40545499 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:9NCh2KrpzMv1gt5H5O1PZCoaV5vxL9V00zAX/kB9WHVpW+SFis Gjm+ka3xfoiDAXHEotg8yEJbPoex7h3LRy5pQcOqrnYRn+tAKTXeRfxKbB4xmlIS3x8eZByb xtGpIVNPTcBUV35PyU3CCWCNAlqePozImNpcPzi0hgVhtrbaYI1XYaNi++HldtTAdLQboVfa D92uN9qzCteWsaY62AbxFoY8H5q8DWj5WjWBYaBnccgzWmty+i67LxDnGjr3Qjeg5IqI1CzU H11zbXy4/mmPG9xx/a2Qbonu5rseqk8PRvLoihjsAULx/llwqnYp9wMofywQwdkaWUx3sB1P XKvhc8L+R/gkmhAl2dkF/W9CTLlBYo9nP4xleTjRLY0LPEbQN/MeVtr8Z9UHLimi4dleA56o 1n9SalkqASKhX6kCH097HzJmlXv3vxm1UOu6oulXBFOLFuD4N5nMgk025+NowPJy7+4JBPKp gUMOjsoMxbdl6XdBnizw9S6e3pWnwyGyGPSVQZtvqU1CBLnGt4w1Fw/r1noks9 X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40545499" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O6R1bRtfnaMG1VyI6gla0ZC2OzHY9+J0GJhXzmaZVnDwvyCumRpjoCwxecgK5cyRVoG5sEyakI0U/Uw3F8PLnKC6ZKToj023GioXMOeY4D68Kie9kqxSfcbfy/Wnw2wrHeSyA7umDsnWUN2fwREd17yTB+Mulyf375zHAMPuQYKRsCZrsfgY0IgwLdOWMhnn+0XIRBl6LpB2dU367l+jalr+l5c5I+32C4rMnOzb2cYWnHXXNDUtwbQ7PtJkC1qzvvrCSZzFYgwLB0EUtpCXeXDEAQt4HSeyzS3peC/miRSQRF5TkuoA+YLswwfZzsbdRuaB7GRTF7Q9E96FVyz3iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ATUqzH1qQW24zHt8gWyGrgI3bjAA4vJXVL7l6nZ/QcQ=; b=i0zitUg0x3h3G4KEIQccro8tRY/Y13rHr3eqY7E0bfTha1jkjzm68N3owC5tRz4FxGDVdOhRAs+S4CHIkvY2dKipNWHBGEFhb5yKRacmAht4O4WJgXv7enJBkGCsneHVXHtaxgZdqcPFZ7u6FhhcI9sNlkLMQcBgtYA6nmRdGO4WdAFootLvzyIcAJvCD++exqYhPd4zt3C/65ZswDHZslZh3M0OjifEK0tzfQvmQhyKQzzznudziENJa1XyPoK41PisEpjdEwBtxbM7BJHU3sBithCy21urXzNEPtBtoSA4f5dUsZnIyD68EfWs4KnOl9L6UujWkLfeJnxJ0O3v8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ATUqzH1qQW24zHt8gWyGrgI3bjAA4vJXVL7l6nZ/QcQ=; b=K8+tiS5EvbJovhv80DDTBKu1pmFYZ447Vfjgxo912QYn/dl44ugnRKOmMSuEADja8c0vY0BzoFOJhLGsK0uD41nFygR01MpPRhFMi+CpUMH3rDXPEUO+fT+y2hvxel072gnuU2j6PeiBYMttuBch1L5XSLLPBhzgna7WzQw8iAw= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH v3 07/11] x86/dpci: move code Date: Wed, 31 Mar 2021 12:32:59 +0200 Message-ID: <20210331103303.79705-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0100.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::16) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c6df4d8-d138-4cce-6bed-08d8f430d099 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JuB7cRfgXRCIY6UngSzwRfzM60q+bvW2x9w7sWLbpN4OpNf2ezFPfDOu5EwkK5PxFtv+NhNzpWE9V4uwkv/UbJ74DYjut67yDyLYg1Myv++YaaTdSWScMYUKLZjYM66eEBjRHF3xW+Opej9MU2N39wfpmVia1YoPKK7pvw19hfEZTe+sfCnqFhwoYQXHWzCgoOJtNJc12c0gNVD4KxctiszPDx9ekKVVRQFLbTWuksybbLeHPeWkADWApQ3S+DEBwgsTVZe3RYJKZynI9afFpwrpMQlNDkwyodRKlMdmABemtG0XsUl96KmrjDyGFrGIeilS4DEpmdnFKGCowfgxWQlRcyyXlR0qxBnuZAPRC6HzgaD7RpZwc3ZH4VV+KtWYTKnRZ9pFA+Mn2Omm40bNqRDOVp5s2l5bxn6y8DG0qtiwoYIfqBVrN3CFh4jRnoXbwvghQlusgZeHqqJJYcfHNb9S5Hz4WGA/Q1C6oqZI6zAvuPpdeh0qqWP4ye3U2mMEkDv1UJtRl/68mnuWeq8HsS2x24awsAk1rXgwUvYGxMuHYDRsZUrko2DLicHRdyyqhLI14WU+Q73iIgvRk2uROHq/DXtpnKScyuhsllhe5nExC4lb37FW93MQS08pqrHYVAuDXl3i46rnXiOLvYNd5A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?3YPR8+HVWYDaeWCbaj1U/BWScHYoxs?= =?utf-8?q?17dU9BXe3ZL1fUHxP2861goQXv5EeOI2DpQF1qrZJPBn4Xo4mQr5ZD+lgvoEmvTYV?= =?utf-8?q?6+wFDONMqapTWMYFXbBGODWxUw3k3yQAvRyB8Xkp4n31nKNhfsfT8crjvzuXOopFV?= =?utf-8?q?FanePlTtvV7zrkFpQuiHDqNjW7UCNcxiNDJrWkr+OE691dT4JiN/pmoONd/9vjLVL?= =?utf-8?q?Tu83FfMwrnGByeC+6/0EfOVwfJU4DtOycZd/Wzup8q/tPMdH0w8G7TKrLB4fDnhQn?= =?utf-8?q?pNn00n7+uANN1FNNmAgUMVddfKqnZ47UVnWNFK7/Obo6o5cdqFlcIaMpLSFzY7WAL?= =?utf-8?q?n6evpNK4wLLc3WnjvxsZMjisEMS6kvntFv3BxgDdm8klQIxKkXfvMM7A9+64/uQXD?= =?utf-8?q?Hd7siUtcokI4lcTIyK/wm+Nwd1J4tnrQTIxPUYFUW4Yv3ZquADQP/MJSn9MUlyxJo?= =?utf-8?q?PloAzG9Tnw/HRHBP93W/27srCygLAOGqv0wWvSJXfbdLz6bQiAPQMjYd3jieOxcIj?= =?utf-8?q?8M/vMQmArYNIWZ6qve0MhqzyxHHACJlWsw2wlmrsmqjZoptfOcZ8XiL8RGjGhYXWW?= =?utf-8?q?ny8A+nR4wuTND17onYtX7n3ihtU9HXfct2b528iFRSpPePm3XGO7qt0qJdGnAdEJG?= =?utf-8?q?N79RsOomBnKk/nKY1pi9dYOG0IAgLOAgh3ZO7gE1kzmF+R1Q1kWC4laleFVZ1Uxar?= =?utf-8?q?gz1PGDUxFUMf5Wwpn019yCpluDnjjQxaZfhAaMb7qQfEZfCZ9du6JUQmz1RgYmFe/?= =?utf-8?q?pI/YEo+Z8iUMBAaU3bLlNECsHFfxhhrCv07YLVp9OPCznZqtZu1PI0aAUsU3nSc91?= =?utf-8?q?7Ul8Vts6C6D8N4YWjOU708mvKFx01gWLHFeUazIcaq7Px491eUcwuZ44x+d1yKrmL?= =?utf-8?q?v9D+09i8sZj0Vc4rHIygAkUBSEl1ec0kmzcmnhrfx4C05XKXYxB4Z7NivE7NvXpxw?= =?utf-8?q?JJunZNejo0Q5RjmtCRL8qA63arf69fDGFg9tAmGqnXWIAY8y3gZnPsTvQ7uePc0Hw?= =?utf-8?q?l9BlH63Rx4dbOUcJrack2vWXXFu7ucWbsuFOEuxItNeuDDF2uG6Wl/kbh5cIiWZsm?= =?utf-8?q?9fLh5bT1rBxbsN4gwzYCGyOlPxiMQZFFzvwR9SFKIACdPIV0wHDiAsaFhUoypAnvo?= =?utf-8?q?ESbZAlpZGceJz1miIiLLVHKmSRC3oilp9GIS4/3H5UERX1l8WM6MX1k1FDP6YwF/q?= =?utf-8?q?sIzP1zkUzl/GnYl0VaTITMB1p1bJFJWfNMvywUkzqjBgprGTqN95ABeiWuyqUSZoP?= =?utf-8?q?WVRECzhAPeN0f/?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5c6df4d8-d138-4cce-6bed-08d8f430d099 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:16.9024 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: k1Vef2Js+LNx3GeP55HIspzoUuNe2uflFDTbMtxBH+Pef8qaUlK8aOfyUPtqcbBem/PirJOm/QEGx4bz8th5Lw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com This is code movement in order to simply further changes. No functional change intended. Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich --- Changes since v2: - Drop one of the leading underscores from __hvm_dpci_eoi. Changes since v1: - New in this version. --- xen/drivers/passthrough/x86/hvm.c | 164 +++++++++++++++--------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c index 2331af896d4..ecc7d66e600 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -205,6 +205,88 @@ static struct vcpu *vector_hashing_dest(const struct domain *d, return dest; } +static void hvm_pirq_eoi(struct pirq *pirq) +{ + struct hvm_pirq_dpci *pirq_dpci; + + if ( !pirq ) + { + ASSERT_UNREACHABLE(); + return; + } + + pirq_dpci = pirq_dpci(pirq); + + /* + * No need to get vector lock for timer + * since interrupt is still not EOIed + */ + if ( --pirq_dpci->pending || + /* When the interrupt source is MSI no Ack should be performed. */ + (pirq_dpci->flags & HVM_IRQ_DPCI_TRANSLATE) ) + return; + + pirq_guest_eoi(pirq); +} + +static void _hvm_dpci_eoi(struct domain *d, + const struct hvm_girq_dpci_mapping *girq) +{ + struct pirq *pirq = pirq_info(d, girq->machine_gsi); + + if ( !hvm_domain_use_pirq(d, pirq) ) + hvm_pci_intx_deassert(d, girq->device, girq->intx); + + hvm_pirq_eoi(pirq); +} + +static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) +{ + struct pirq *pirq = pirq_info(d, gsi); + + /* Check if GSI is actually mapped. */ + if ( !pirq_dpci(pirq) ) + return; + + hvm_gsi_deassert(d, gsi); + hvm_pirq_eoi(pirq); +} + +void hvm_dpci_eoi(unsigned int guest_gsi) +{ + struct domain *d = current->domain; + const struct hvm_irq_dpci *hvm_irq_dpci; + const struct hvm_girq_dpci_mapping *girq; + + if ( !is_iommu_enabled(d) ) + return; + + if ( is_hardware_domain(d) ) + { + spin_lock(&d->event_lock); + hvm_gsi_eoi(d, guest_gsi); + goto unlock; + } + + if ( guest_gsi < NR_ISAIRQS ) + { + hvm_dpci_isairq_eoi(d, guest_gsi); + return; + } + + spin_lock(&d->event_lock); + hvm_irq_dpci = domain_get_irq_dpci(d); + + if ( !hvm_irq_dpci ) + goto unlock; + + list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list ) + _hvm_dpci_eoi(d, girq); + +unlock: + spin_unlock(&d->event_lock); +} + int pt_irq_create_bind( struct domain *d, const struct xen_domctl_bind_pt_irq *pt_irq_bind) { @@ -860,88 +942,6 @@ static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci) spin_unlock(&d->event_lock); } -static void hvm_pirq_eoi(struct pirq *pirq) -{ - struct hvm_pirq_dpci *pirq_dpci; - - if ( !pirq ) - { - ASSERT_UNREACHABLE(); - return; - } - - pirq_dpci = pirq_dpci(pirq); - - /* - * No need to get vector lock for timer - * since interrupt is still not EOIed - */ - if ( --pirq_dpci->pending || - /* When the interrupt source is MSI no Ack should be performed. */ - (pirq_dpci->flags & HVM_IRQ_DPCI_TRANSLATE) ) - return; - - pirq_guest_eoi(pirq); -} - -static void __hvm_dpci_eoi(struct domain *d, - const struct hvm_girq_dpci_mapping *girq) -{ - struct pirq *pirq = pirq_info(d, girq->machine_gsi); - - if ( !hvm_domain_use_pirq(d, pirq) ) - hvm_pci_intx_deassert(d, girq->device, girq->intx); - - hvm_pirq_eoi(pirq); -} - -static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) -{ - struct pirq *pirq = pirq_info(d, gsi); - - /* Check if GSI is actually mapped. */ - if ( !pirq_dpci(pirq) ) - return; - - hvm_gsi_deassert(d, gsi); - hvm_pirq_eoi(pirq); -} - -void hvm_dpci_eoi(unsigned int guest_gsi) -{ - struct domain *d = current->domain; - const struct hvm_irq_dpci *hvm_irq_dpci; - const struct hvm_girq_dpci_mapping *girq; - - if ( !is_iommu_enabled(d) ) - return; - - if ( is_hardware_domain(d) ) - { - spin_lock(&d->event_lock); - hvm_gsi_eoi(d, guest_gsi); - goto unlock; - } - - if ( guest_gsi < NR_ISAIRQS ) - { - hvm_dpci_isairq_eoi(d, guest_gsi); - return; - } - - spin_lock(&d->event_lock); - hvm_irq_dpci = domain_get_irq_dpci(d); - - if ( !hvm_irq_dpci ) - goto unlock; - - list_for_each_entry ( girq, &hvm_irq_dpci->girq[guest_gsi], list ) - __hvm_dpci_eoi(d, girq); - -unlock: - spin_unlock(&d->event_lock); -} - static int pci_clean_dpci_irq(struct domain *d, struct hvm_pirq_dpci *pirq_dpci, void *arg) { From patchwork Wed Mar 31 10:33:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AEC9C433DB for ; Wed, 31 Mar 2021 10:36:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D871F61582 for ; Wed, 31 Mar 2021 10:36:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D871F61582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103854.198103 (Exim 4.92) (envelope-from ) id 1lRYDC-0005Cn-H1; Wed, 31 Mar 2021 10:36:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103854.198103; Wed, 31 Mar 2021 10:36:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDC-0005Cd-DE; Wed, 31 Mar 2021 10:36:34 +0000 Received: by outflank-mailman (input) for mailman id 103854; Wed, 31 Mar 2021 10:36:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDA-0004so-K1 for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:32 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d1731d54-c7bd-4d29-811e-326e91ca0113; Wed, 31 Mar 2021 10:36:26 +0000 (UTC) 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: d1731d54-c7bd-4d29-811e-326e91ca0113 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186986; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=BsyDEsX9ceA4dUbZnZwjzJfmI6TlX31Agx0NKPinq9I=; b=QvR6CbVjD8uXFav6RYBFhxbe1NFNIpE+bg8cxdWnczJzo8Ul9OT8K6Us CI6ftpEIfBihzPhbU6znlpJwe0XKywmHCJ2EivLo0krRfNCiA1fMzy6TC VQNSGKJ61B/yZBuK9gtpzEvdjR7FX8oZyrt8FtPbygy8bfkQ8a+H2/Qs6 U=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: zYVZcCUJVGd9kP/ghbTciBOjDI/YoeMo6o9URj9xFSwvMX/sS+pty5haJzKoCz/M1NHwNxdItz 12jr8X0QScwvb6grJwJKxSB0f/dmiQqlXp0H+JHpxbOP6IF3I1C7+gvhQVxDQ7UEAlodLW69hL oE2eMlmtwPkh8ySbnf5OqBH9C1tptA/MLg918FUHkGQE7zRiaZ+hS8Gp1mnSJuFYPuJXRRupa0 2C+X8MLxlVGJcO1UcYBlz9QLl0mOL74P8VYauwNYAGFY6HfL+B3qJVOzS9L3qX1aV3JhSGXUbJ 2KQ= X-SBRS: 5.2 X-MesageID: 40415685 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:CbFAdaCwg2Ph7NblHegptMeALOonbusQ8zAX/mhLY1h8btGYm8 eynP4SyB/zj3IrVGs9nM2bUZPufVr1zrQwxYUKJ7+tUE3duGWuJJx/9oeK+VHdMgXE3Kpm2a 9kGpISNPTZEUV6gcHm4AOxDtYnx529/Lq1gPrFpk0NcShBQchbnmNEIyycFVB7QxQDOIEwE4 CS6tECiz2rf3kWacrTPAh4Y8HoodrXmJX6JSMXHhJP0njysRqEyp7fVyKZ0BAXTi9Vzd4Zn1 TtvgTl6syYwpeG4zDG0Wu71eU1pPLAzZ95CNWImowpLFzX+32VTaBAf5HHgzwvuuGo7z8R4a nxijMtJd565X+UXkzdm2qV5yDa3Dwj62DvxDaj6BOJy6yJJ0NJN+N7iY1UaRff4UY71esMqp 5j5G6Fq4FRSSrJgSWV3am4azhRikG2rXA++NRj6EB3bI12Us41kaUvuGlREJsGARvg7pEmHO REHKjnlYhrWGLfQHbDsmZ1xtuwGlw1AxedW0AH/veYyj5MgRlCvgcl7f1auk1F2IM2SpFC6e iBGqN0lItWRstTSa5mHu8OTea+F2Sle2OCDEuiZXDcUI0XMXPErJD6pJ8v4vuxRZAOxJwu3L zcTVJxrwcJCgLTIPzL+KcO3gHGQW27Uzio4NpZ/YJFtrr1Q6euGTGfSWopj9Crr5wkc4zmcs f2HKgTL+7oLGPoF4oM9Rb5QYNuJX4XV9BQlc08X36Iv8LXOqznvuHWa5/oVfjQOAdhflm6Lm oIXTD1KskFxFusQGXEjB/YXG6oWkGXx+M0LIHqu8wojKQdPIxFtQYYzX6j4NuQFDFEuqsqOG 93ILbtlLKHtXC7lFy4q1lBC154NAJ48b/gW3RFqUshKEXva4sOvN2ZZCR00GaYIAR8C+fbCh RWqVgy2a/fFe3f+QkST/acdk6KhXoao3yHC70GnLeY2MvjcpQkSrA8WKJwEg3PPwdvmRljrV pCbANsfD6dKhrezYGeyLAEDuDWcNdxxC2xJ9RPlH7ZvUKA4f00SmAjRD6oW86PiQMITz5Z72 cBtJM3sf6lo3KCOGE/iOM3PBlpZH6MCLxLNgiDeb5Zg6vmYg12UGeMiwGLkh1bQBuYy2wiwk jaaQGEc/DCBVRQ/kpV1avn63tYXGSQdUAYUAEwjaRNUUD9/lpj2+6CYaS+l1aLYlwZ2+cHLX Xuej0JOD5jwNixyT+YkDuPDm8d250rJ+DRZY5TNY376zeIEsmlhKsGF/hb8NJZL9joqPYMSv /aVAmPLj/0YtlZrTC9lzIAAm1Tp3Ylm/+zh0Ggw2i8wXIlAf3dZH5hXKoWJtmA727iA9aEua 8J+e4djK+VCCHWbNXD9IT8KxhkATnXqXStT+4ppYtP1JhC/IdbLt3+a3/wyHpD3B8CN8/6m0 MVfbRj7Nn6S/pSVv1XXxgcw0Egm9uOJnY6qwDaAucxelc2kn/QVun5lIbgmP4KCk2FqBCYAy jmzwRtu9PEVTCEz7gUFuYZJnlXclE17B1Zjam/XryVLAWhbOdY+lWmdle7bb9GUaCAXZEdtA xz7d3Nv+iZcUPDqU3tlAo+BqJF6GC8R8yuRCqKBO5T6tS/fW22vZHC2r/7sB7HDR2ha0oZgo VZdUsfKuR74wNS87Ef42yVUaz4okUsjl1Exypo/2Sdg7Sb3A== X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40415685" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ahpTBpugP3SX26HdOQ1ebgu/ly89uC4EMv9yf3/4CT0fXDk+gHAs9HR0cAO+CDAopmpjN7re47r/RXo2xdfTH/aRI/d3651sTB5616oI+VQvEuMAU+Tj+W8G/RZTer6Tky/e6vqj5/lpfspZdQ2DsF4R61b04ibTNqPSBQ70c/8SZ0MP66wcTV2qgmjSqNp+z0xGi4rClN68s6x1139oTEz6ej3U0ZytQHTJ2A/vatOTcla7ozfMnghqRJ4fpMcZEfC2h/Dk5uWjbuLIxMclcQC4OJ5BzU/PNKBlJws3R56QFymvtebWiIfaSCNLtESkGqIjIalHBhM0/J//yWWOXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wPR5XbW/RU459tEveSX6lE/a/vHm/2wN5mOhp/77/C4=; b=CN6hkp/xR+FUr6gc+OP6wghJhOuvjw0I2RZjl2ih4BfY+96hOuGCHWcAtyt64UYf3oNKqdn5v4H+keTho0tvCt1qJmfHbOdAQ9LHo98yywvzCzO9pVujh7pgfz2AxdcIunGnuOWafR9JcHqmcStAWvP+G/Q/eXemcgeWah5UyjM7op58D8iiTjuFrsH89G/qYZRy4J3X9tqLlYs77Y3k9aak9X2M9NDSGvP7RZ4/L36IKUnAMTbgYhbDZXCNwAYNhQ4ZhSdtWiYdqQfqRAuDndc4T7lqfdAr2Nsy0Azu7oStABiQXQesjQUT5sYir2lJUn55cbaKxz+ooXTBSukBkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wPR5XbW/RU459tEveSX6lE/a/vHm/2wN5mOhp/77/C4=; b=tlj5hnsks5ipoidLFez6oQE8929rdsL/ilWx2X+Rj4oLtnZK5Q33/KnhsUNpkmWra9PImJd0gHn10PARADxdfP6JsFNbBlAQjpn7xZIV3aOCWFAfMAqYdh4lexhFq8hQKWtYilOb43Ds9qc6vd1+0bMdnCiAIHsbeoE6FSRRPqo= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Paul Durrant Subject: [PATCH v3 08/11] x86/dpci: switch to use a GSI EOI callback Date: Wed, 31 Mar 2021 12:33:00 +0200 Message-ID: <20210331103303.79705-9-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0112.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::28) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ea4d173-e4e5-4353-afb9-08d8f430d3d5 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dn26CJMBmePfHhfGdfwX4yw9HuWpvYropm8lJ82PrzSm+Cit7ZidCqq4Rd2vjOHf/oXknEe4wlH0CRyu5g6WoCwfVa6tVuEZt5SH0gp68nEUKWZAVa+JAtcoDaDfqvw11xsyXM6nj09poNORdYB15JHcTMkLRNvt/WkubbcDtw/WZ3zkFlHKfYWF/D8FxD2QjlIVU14Q1exUIAcmfvEAlWEr3n+AxQc6TkCdZHv5I6wMvY2rB/W5cjL9B4rd2J/WMwHWVC+IIm/7zBqCJGY12B03LjEPaaWiVxxxJo/APi9zcE9gg8Caiklqk5OdkwkciM/utrmb3700yTmovuslRs3wCsuvI2xgkE9cB/Qx+1j6eAcb+pBxvlRWYp2ylVNIoXb37DRLetGRD69pZZyaqxI/a5ocYRhjTm7vgABPvznPKoVsGNtvVm4tSBmhEsGfNbFSkmLyr/B8YQr4+np6O+FkorkITguzlUMI6LUxtGOqvRmmAjIIUYRg7OaF/1Cr8bcYHv2kYsOw0ky1DRt4Onf5e3I6pCSd//G6NgyMjM7p8vUtcfudjniVwTE9qMjHPaCbtzi6Mfr+wtaQ4Ulmy3nTKCqNrD1wn0l2Lvk5UtZHuZ7NF3zXVx7hJ/xY4PdkMn7nibRrx2g7lp5fgERTFw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?jIm9Tb59gBMkaGmKHsPDnxPkzwde0D?= =?utf-8?q?TS1ktsrstGBcd69mfUWGmPPoJeG8wJQJxyZMLULTfB8WI7RR1mxIdpJkIjyO8/chK?= =?utf-8?q?bCi57V99xzXZwtAv7tOnxmTWvV/w5rQc8PDd/kOIllWkYMAyNlS1OydKCwgK0L6wh?= =?utf-8?q?Hh8YKWM0EACKTVZUPGDy2llFM116D3o3oGEhd5qy8U4axiouCDhxMjBg+wcNSiAUy?= =?utf-8?q?WhgSYh8FEj4R0SDXIPLFhTUKLiS3wIKPVtv2c+gqrWRhDssWh9ljt5TKa+HAzsqxX?= =?utf-8?q?3tn2OfOY1oFYS5JtJExSeBwA9jedb+g13ghR1LzqO6roZcJzahm5Cm6tm4LhDF4nx?= =?utf-8?q?uX9OrvdSFadNcXI4BileqGiOErURpsP5iHtls6umJ9HeZfSVLwGhVhUW/FnhLYUt9?= =?utf-8?q?NfcGw9UsuKKZrcTPF8xdtcBM2A5W5ebHTUqZCVp+AU1Jm+Qt/QRXekQpI6nzi1Ef3?= =?utf-8?q?lvRIHeVummiIJofcAf0KdkSaWPs5LZ7bKyWRt5IMRP45FLMljMxbUM1zL6scwzmZ9?= =?utf-8?q?qmhc1t0w8s8d5uZNDD35mkmsdDdZs3IsMTXPM2A4+s/gRxr0j4PGIIF10UPgZs1DY?= =?utf-8?q?SlR3A3TsRgJyfNtw5RG8LpvF1X1nWKF+2/vwuq0cyNw0O+7BJ3TX5tkBD0N0GukfH?= =?utf-8?q?t1uwgmTxueJQtIEVleZ/Ghm/8CmdaZ0rmu9ZN/J52lBe6HrEVXdUg1K9+Eh+AbKmv?= =?utf-8?q?7UCKRmBOq9lgmpi6HDS6JirqMyH5RvQsy1dyhUItCMDUKOY8c5FKcfRG9kh9CYLhV?= =?utf-8?q?zZQHMBcQSh50cTxm1DAucH/Lzht8bCQNXsmG/LSeRtvj/yjEos9LFXlRqvq+9aR3E?= =?utf-8?q?N0jxszZEdTpRK1w83v/gd37yqZq5a3IFDrCLsMHaxgpTP/si83LjGHqmmm4aRhpCn?= =?utf-8?q?5DrGIXF+wQTwyNGaLTecM993kAAy+d2OmarpEP4jP1xK0Z6uD08R5vLub/MisyZbv?= =?utf-8?q?CtAqWxaJ5H25/c1hCuvfVUsIr+I0QmaLvuXjBMZ4l5d3QFf1ssxQxCRYHEO3olX48?= =?utf-8?q?d6NuEOIhynv1R3V4YT9Y31LgzsJpMmZhsoE+ecUBncHVV/im9Y6mM8BVXqutfV2k+?= =?utf-8?q?qB2ajhE34F7+3cR6Y4Xow1LpirT94T2RRNLsdt2vsIFNyIR4SjkpfI8MGxAIXHNKp?= =?utf-8?q?0Qoc1wJ559vFNXRnX2xBWzimU/NPYVpEM2hBTz32eMEXjfih9CbE+bSMp3w3rrE91?= =?utf-8?q?WvyiMVHZtk4LjExgQ123p1u6NNNBdBCqWPVc0owdP2f+aibLSH2prLDhvtStAmIRC?= =?utf-8?q?uLTHbe5dDPW9hH?= X-MS-Exchange-CrossTenant-Network-Message-Id: 0ea4d173-e4e5-4353-afb9-08d8f430d3d5 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:22.3913 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7Ixtz/qpvq4IYbVyS+F5NiN1kFk3eP4FcyjA4yz3616xs1KscfL8Si9KmXZ+bTwwAzM3sKmkla8O4KvwGdKB1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Switch the dpci GSI EOI callback hooks to use the newly introduced generic callback functionality, and remove the custom dpci calls found on the vPIC and vIO-APIC implementations. Signed-off-by: Roger Pau Monné --- Changes since v2: - Avoid leaking the allocated callback on error paths of pt_irq_create_bind. Changes since v1: - New in this version. --- xen/arch/x86/hvm/vioapic.c | 8 ----- xen/arch/x86/hvm/vpic.c | 2 -- xen/drivers/passthrough/x86/hvm.c | 54 ++++++++++++++++++++++++++++--- xen/include/asm-x86/hvm/io.h | 1 - xen/include/asm-x86/hvm/irq.h | 1 + 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c index 099c29466ba..4cdb95ce835 100644 --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -284,7 +284,6 @@ static void vioapic_write_redirent( */ ASSERT(prev_level); ASSERT(!top_word); - hvm_dpci_eoi(gsi); hvm_gsi_execute_callbacks(gsi); } @@ -420,13 +419,6 @@ static void eoi_callback(unsigned int vector, void *data) ent->fields.remote_irr = 0; - if ( is_iommu_enabled(d) ) - { - spin_unlock(&d->arch.hvm.irq_lock); - hvm_dpci_eoi(gsi); - spin_lock(&d->arch.hvm.irq_lock); - } - /* * Callbacks don't expect to be executed with any lock held, so * drop the lock that protects the vIO-APIC fields from changing. diff --git a/xen/arch/x86/hvm/vpic.c b/xen/arch/x86/hvm/vpic.c index ca484c31b6a..e0f3f6276dc 100644 --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -237,7 +237,6 @@ static void vpic_ioport_write( ASSERT(pin < 8); hvm_gsi_execute_callbacks( hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); - hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); __clear_bit(pin, &pending); } return; @@ -288,7 +287,6 @@ static void vpic_ioport_write( vpic_unlock(vpic); hvm_gsi_execute_callbacks( hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); - hvm_dpci_eoi(hvm_isa_irq_to_gsi((addr >> 7) ? (pin | 8) : pin)); return; /* bail immediately */ case 6: /* Set Priority */ diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c index ecc7d66e600..4ae678d69b4 100644 --- a/xen/drivers/passthrough/x86/hvm.c +++ b/xen/drivers/passthrough/x86/hvm.c @@ -252,9 +252,9 @@ static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) hvm_pirq_eoi(pirq); } -void hvm_dpci_eoi(unsigned int guest_gsi) +static void dpci_eoi(unsigned int guest_gsi, void *data) { - struct domain *d = current->domain; + struct domain *d = data; const struct hvm_irq_dpci *hvm_irq_dpci; const struct hvm_girq_dpci_mapping *girq; @@ -477,6 +477,7 @@ int pt_irq_create_bind( { struct dev_intx_gsi_link *digl = NULL; struct hvm_girq_dpci_mapping *girq = NULL; + struct hvm_gsi_eoi_callback *cb = NULL; unsigned int guest_gsi; /* @@ -503,11 +504,23 @@ int pt_irq_create_bind( girq->bus = digl->bus = pt_irq_bind->u.pci.bus; girq->device = digl->device = pt_irq_bind->u.pci.device; girq->intx = digl->intx = pt_irq_bind->u.pci.intx; - list_add_tail(&digl->list, &pirq_dpci->digl_list); + girq->cb.callback = dpci_eoi; + girq->cb.data = d; guest_gsi = hvm_pci_intx_gsi(digl->device, digl->intx); link = hvm_pci_intx_link(digl->device, digl->intx); + rc = hvm_gsi_register_callback(d, guest_gsi, &girq->cb); + if ( rc ) + { + spin_unlock(&d->event_lock); + xfree(girq); + xfree(digl); + return rc; + } + + list_add_tail(&digl->list, &pirq_dpci->digl_list); + hvm_irq_dpci->link_cnt[link]++; girq->machine_gsi = pirq; @@ -515,17 +528,44 @@ int pt_irq_create_bind( } else { + /* + * NB: the callback structure allocated below will never be freed + * once setup because it's used by the hardware domain and will + * never be unregistered. + */ + cb = xmalloc(struct hvm_gsi_eoi_callback); + ASSERT(is_hardware_domain(d)); + if ( !cb ) + { + spin_unlock(&d->event_lock); + return -ENOMEM; + } + /* MSI_TRANSLATE is not supported for the hardware domain. */ if ( pt_irq_bind->irq_type != PT_IRQ_TYPE_PCI || pirq >= hvm_domain_irq(d)->nr_gsis ) { spin_unlock(&d->event_lock); - + xfree(cb); return -EINVAL; } guest_gsi = pirq; + + cb->callback = dpci_eoi; + cb->data = d; + /* + * IRQ binds created for the hardware domain are never destroyed, + * so it's fine to not keep a reference to cb here. + */ + rc = hvm_gsi_register_callback(d, guest_gsi, cb); + if ( rc ) + { + spin_unlock(&d->event_lock); + xfree(cb); + return rc; + } } /* Bind the same mirq once in the same domain */ @@ -597,12 +637,17 @@ int pt_irq_create_bind( list_del(&digl->list); link = hvm_pci_intx_link(digl->device, digl->intx); hvm_irq_dpci->link_cnt[link]--; + hvm_gsi_unregister_callback(d, guest_gsi, &girq->cb); } + else + hvm_gsi_unregister_callback(d, guest_gsi, cb); + pirq_dpci->flags = 0; pirq_cleanup_check(info, d); spin_unlock(&d->event_lock); xfree(girq); xfree(digl); + xfree(cb); return rc; } } @@ -709,6 +754,7 @@ int pt_irq_destroy_bind( girq->machine_gsi == machine_gsi ) { list_del(&girq->list); + hvm_gsi_unregister_callback(d, guest_gsi, &girq->cb); xfree(girq); girq = NULL; break; diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 9ac3e4f48f6..a05bdbe5555 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -101,7 +101,6 @@ bool handle_mmio_with_translation(unsigned long gla, unsigned long gpfn, struct npfec); bool handle_pio(uint16_t port, unsigned int size, int dir); void hvm_interrupt_post(struct vcpu *v, int vector, int type); -void hvm_dpci_eoi(unsigned int guest_irq); void msix_write_completion(struct vcpu *); #ifdef CONFIG_HVM diff --git a/xen/include/asm-x86/hvm/irq.h b/xen/include/asm-x86/hvm/irq.h index 0828c01dd18..f49c4c3b6e5 100644 --- a/xen/include/asm-x86/hvm/irq.h +++ b/xen/include/asm-x86/hvm/irq.h @@ -156,6 +156,7 @@ struct hvm_girq_dpci_mapping { uint8_t device; uint8_t intx; uint8_t machine_gsi; + struct hvm_gsi_eoi_callback cb; }; #define NR_ISAIRQS 16 From patchwork Wed Mar 31 10:33:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D425C433DB for ; Wed, 31 Mar 2021 10:37:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 95A8860C3D for ; Wed, 31 Mar 2021 10:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95A8860C3D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103864.198139 (Exim 4.92) (envelope-from ) id 1lRYDW-0005X1-07; Wed, 31 Mar 2021 10:36:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103864.198139; Wed, 31 Mar 2021 10:36:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDV-0005Wm-RI; Wed, 31 Mar 2021 10:36:53 +0000 Received: by outflank-mailman (input) for mailman id 103864; Wed, 31 Mar 2021 10:36:52 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDU-0004so-Ke for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:52 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 848fdff6-3a6a-4e73-975d-5606b01201b4; Wed, 31 Mar 2021 10:36:31 +0000 (UTC) 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: 848fdff6-3a6a-4e73-975d-5606b01201b4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186991; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=NZnmw6vdqBrw2HPwEJs9LRsvlJ7YMCZXRIR6F1TNqXQ=; b=Y6gnRn3/AlNV9F//I+VVFamzBmulVq3teDNd0llH7sQVs1oON+UxSrSp JqswhCSgB7Q7M12Xk6PDs77xH9VYFXglyaFTkUiEnH3DBa/AtyJedvRrr FlvZ0PpRcftuZgd5aJAlOSzId4dO3tK+CwV+Uff7lhxpo2jgKx5eloqJ0 c=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: GzYTQ1HxW4/iEHxlp2hC6o+GzQMoG5d0fUIe3/pRAVPJraW/n3TDyEZFC07via+8zjiwpi0wVc whzUJTXHFmdgyYsAGF6gSqIc6OBoI1TYrUzOctuhoZb58JZQfia4zBrp4zAl+Xkmzyc+sKWIB2 XZBKXgmeSu/RPHlPu15yRTo5AhE35ksYLV9w1EutHraI2rIoZN5ShsI4yEkYH7Ct2Ch53aeECO de5GAgKBkdtUgmmVdpDM4Wqij899u08/dX7BzYh8qsG4psfO6WzVx36NlhQ0BtDX0d98VFiFO/ HZs= X-SBRS: 5.2 X-MesageID: 41994610 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:5Z2CPqzAJ2ZG66JsG6yaKrPx9uskLtp033Aq2lEZdDV8btGYm8 eynP4SyB/zj3IrVGs9nM2bUZPsfVr385lp7Y4NeYqzRQWOghrMEKhOz6vHhwfhFSr36/JH2c 5bGZRWJdXsATFB4vrSzxK/F78bruWv1ICNqaPgw2x2TQdsApsQjTtRLgqACEV5SE1nKPMCdK a03cZMqzq+dXl/VK3SakUtZOTfu8bN0KvvfB9uPXUawTOThjCl4qOSKWn64j4iVVp0oIsKwC z+vCHSoo6itPy6zRG07R6o071m3OHP5/EGKMiFis0+IijhhACydO1aKsC/lQFwms6DwhIHl8 TNvgcBMq1Img/sV1DwmzTB8U3B1ysj8HDrw1PwuwqdneXJAAgUJuAEoKAxSGq812MQ+OtS/Y gO4kei871QNh/ElDSV3amxazha0nCajFBnrfQelBVkIOwjQY4Ul6Mz1mVPHqwNGSrrgbpXa9 VGPYXn6PFafUjyVQG+gkBfhNilXnEEFhybWEQ1usuMzzhMnHxipnFovfAiog== X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="41994610" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d2Ojk7gvmCog++XfKvxRBCX2dedGlbt9kTsPQ3gTWFf1BC/5PNZWST30tG9c+FqLs3xzoaHt8Cznj9Eh9ysrkEQsux89s7V9QBKIjyNlUD+bfgrtRtAF9lcY9T73JIfwm9iDKbokbqdlc1z8kht2f+ynWepRXr65GMgrcFuRXZZ+LvPZ99I7JBDkSX3GZqfk2jyl9YBqUXVJnHOXBVV0GnYLB5M4CrkS6a5WQPxDpMVbm8UvJnyCGu8T3+l68VXW+SMtrszN4F/3DI90UucpdZ1ii5iB4LNhyvAcZ5EmeKLDzkfStVL3KuyFfQJN5BsKJwx+NDfchGVmE4HcZIB2hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uvejW0nULK+NfwUACCxHzbAooqbar4wdYJPJ8qc6zcg=; b=bbT5V746CEPGMTMzqUwWJEzbuPM+hPhw6fOPzFhfuNo95GZr13T0Jgf9zMpGkcqu8oOA+nBXLCT8Jix/PeYgudYrlSUpayheIqFZMHgbSRkA9xzmT11yJdvflMzvQJhdoJwm3/TQbO11bHSttserEeCjCiq3vBRBdX/knllbiFLqMVuF+onVTo7Xz0aiB7u1DGO//fn29XJ4t3Yqcbcjzrc+tTgZhao+3/KN4EEPE0uAS+Wl25L79prXqNkbMG1iduY2VWHZGiilhR4Hmx00Y4YsPMXmKidmKk9sqw3POCQAq6cQZqLVZR6DbC2v1RtHUGKBwnjHaR7uOrnp3l9w1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uvejW0nULK+NfwUACCxHzbAooqbar4wdYJPJ8qc6zcg=; b=HB2zT/oIfOOy0/9rv2+bWWk4cy+78gf/RNXpLHcP25E6JznNdUb10UKHS2sZel6LLjke4LY41wAXaYB1l6ReT1Z6bVQcI3ib4ens53gvs4vwKEXNrAEBkpey1XWKf4va46sLZGP9ec9igIjKwhBi6GKPm52cTio1m0cPPxi3K4o= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu , Jun Nakajima , Kevin Tian Subject: [PATCH v3 09/11] x86/vpt: switch interrupt injection model Date: Wed, 31 Mar 2021 12:33:01 +0200 Message-ID: <20210331103303.79705-10-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0074.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::14) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fc51022-c600-476c-0387-08d8f430d76e X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CWBMoWg50CVpYeXzJCIsg0l+OuXpEzcGG372ZehWBqSgPv1O7ABsq8iDAAFXIQplDQasHG+/3k6YMBSF5bfLr3E8k186JD9GWC5J68R7NFXaQmObx292vfV09bZj3NDGLV7WqyFO4NgbZtS2pxUtLnefJD1b9tLMl51LJx7vZ06HO7Ye9WmaoPCOg0Sf+IHKiPj530PiTQPa2XbBn5GtxcctxHnc24nvHSOvS8giAdVFlw5QxutGXAgSxNSqTQCGDocIJ2no3xlpc2O0mtPd/zUSLqclcvWBpNorR8watRgSEOsC+hu7CPUVL/iUs5K9j72GsWbIgX1eNSOZitoSnAHIprFTqST/2VwBu7oG5RqWGEu8JvCp2tblICP91h5zogNBXTMyTQJDYodjq/JPq8/jnYB8OvTud1MeZoBiLMViw2oWcd6xHcWZL1w+kZ8YQ+Ww2kYCYPZ/GozkJ7YLHZajsc3rvuhmlLK6N+osK+hGg4+8KPTNFrwOgqRKlN8h6+8YUWX7SwLrftFKUroqtwKWTWfzqT69IAFe4YT+F57ZPPY+pu3kcNlJjo1WEcS3i7sBAPNlo3coMGsfDcgT2dGkOkeB+iwC+VSuq3U+/Q06y8n4nVvSI4zBsjflojqeITHQr7Fj3iCdIxb5XGeeiDvbgaulDk/rooetDc5aHwc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(30864003)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?pzD0HuUJGooGZBkJSVlyoeWYcZ0iMj?= =?utf-8?q?j1TYVdUTZ9zxpDSM4jn07QPkur9EOOYlkg6mSHM2AUqJ1VFvljQ+EksNc2MHkIr4i?= =?utf-8?q?gwHQ09v5xlLpIbsCfwmGKr1zhkFQfo3MRJVIxUw+S6NgwawrhDMxQBh06GKiCmsNe?= =?utf-8?q?r+gt5XqFCG2VXuvya6msfFO8VoysuGe59gRKYaIYR5mzhP5gaJ1TLHu2WGpHBUAII?= =?utf-8?q?HkeKgRLYVX9RTBpL635HB2ST/hubVRC8SmJxsXN/yNq1Clq3HH0ZGP8JqMWVGTCff?= =?utf-8?q?Pm6vQLuH2bieogpTxlJ7hRS7wqWKrlZ64Qnh/I9UWhbsi1B0ckoTw+zsruSuGuXEB?= =?utf-8?q?GPEsKYxHZXxA/dwucjsc3CPShQPvXccOiCLhikc8MRT+m4ihXXB9dd/uqx43aYo1+?= =?utf-8?q?1M6q5H676iREafbMoyd/IniBJRQrvvJgDNN4aS+GYnZjUCAl4NTYqDkibKT50zl72?= =?utf-8?q?uREr1U2kUYXh5vdhe5whjGgLnICdPS2cN36VHpWbvhFRkfvr8+iXLgLAbw4GmULcg?= =?utf-8?q?z3TjFkrYwGTu66SsPNpTnrcIzvSFi53TTUyc/k4o2mdEP9Qc0QpIWejBmsDE4VfKv?= =?utf-8?q?T1wjS8RDKTfCYO0hpFzLY4XY4txSMr+uvZwS0/ZV8Y6Mi0c58E+pku/nGaT8F01oB?= =?utf-8?q?ixEPwleU3YEHA6UhqfPOkYIVUHzVDl4UDMbwKrfMkTEdXhD1jk8Vy/Bqj1fgABx90?= =?utf-8?q?GN5MTccwOjkFGA+E8+9/2/aNyHK7Fsw8YdYlvLngFtXU/05vkR5sX/USntgYf8lYz?= =?utf-8?q?qKF6qULSw/eERpNPw07gcquLeA582zey6Xa9N/M33LAngTTxWg3f4WMG01kaKt5uv?= =?utf-8?q?Has284eHilWZqfMqUha6pE2Ly3UG1RUTK2soRrCGLnrsSnUPNC8ja+o1HjWB0jXgP?= =?utf-8?q?RkD0997HrYuC/Et8p+mT/odtp7hX8LdqB9tFvtfjdSAcpE6EvWxHZgu91z3SJdaIL?= =?utf-8?q?cfUWsjhavvKj5xQ43/h4r7J29XmEJO88Y1H9afhlfxc1evcoXUoWm0BiYMiYtMU81?= =?utf-8?q?h6FwBWAyd7Snsw14VAiciJQzkzHgm2I5HvNWgb+hpLOj4PpCDWmraF/TxxQYVh9oZ?= =?utf-8?q?DQN0DASA0Rk+pAz1q5qA4mfYILHBGUs0cB/5K2FfYxh6skyTdLeT5IiDcRBzGQp8h?= =?utf-8?q?/T4k4DhyXUHWrnmx7gYd93r5JVyly+y7Sa2bMXSw0WysjFtK3wEsUlHP7RB5ZyDw4?= =?utf-8?q?shobhM/RWDq4kBZmGp7HQIKPDAUstLaSGiD+RMW3K3ZmGWP+WVjZXG9BpaNAKvp3z?= =?utf-8?q?d4zXNIpBC0xO6T?= X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc51022-c600-476c-0387-08d8f430d76e X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:28.4815 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Oq/D4JsxTXKPEZp8VZR+pp4Y3uzK1S8PJFomABCQlqW83us1hS5UlrK8jntNbYwpauZUGra09OU4prD9zD7dSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Currently vPT relies on timers being assigned to a vCPU and performing checks on every return to HVM guest in order to check if an interrupt from a vPT timer assigned to the vCPU is currently being injected. This model doesn't work properly since the interrupt destination vCPU of a vPT timer can be different from the vCPU where the timer is currently assigned, in which case the timer would get stuck because it never sees the interrupt as being injected. Knowing when a vPT interrupt is injected is relevant for the guest timer modes where missed vPT interrupts are not discarded and instead are accumulated and injected when possible. This change aims to modify the logic described above, so that vPT doesn't need to check on every return to HVM guest if a vPT interrupt is being injected. In order to achieve this the vPT code is modified to make use of the new EOI callbacks, so that virtual timers can detect when a interrupt has been serviced by the guest by waiting for the EOI callback to execute. This model also simplifies some of the logic, as when executing the timer EOI callback Xen can try to inject another interrupt if the timer has interrupts pending for delivery. Note that timers are still bound to a vCPU for the time being, this relation however doesn't limit the interrupt destination anymore, and will be removed by further patches. This model has been tested with Windows 7 guests without showing any timer delay, even when the guest was limited to have very little CPU capacity and pending virtual timer interrupts accumulate. Signed-off-by: Roger Pau Monné --- Changes since v2: - Avoid and explicit != NULL check. - Use a switch in inject_interrupt to evaluate the timer mode. - Print the pt->source field on error in create_periodic_time. Changes since v1: - New in this version. --- xen/arch/x86/hvm/svm/intr.c | 3 - xen/arch/x86/hvm/vmx/intr.c | 59 ------ xen/arch/x86/hvm/vpt.c | 334 ++++++++++++++-------------------- xen/include/asm-x86/hvm/vpt.h | 5 +- 4 files changed, 143 insertions(+), 258 deletions(-) diff --git a/xen/arch/x86/hvm/svm/intr.c b/xen/arch/x86/hvm/svm/intr.c index 7f815d23078..2ee2332253b 100644 --- a/xen/arch/x86/hvm/svm/intr.c +++ b/xen/arch/x86/hvm/svm/intr.c @@ -146,8 +146,6 @@ void svm_intr_assist(void) return; /* Crank the handle on interrupt state. */ - pt_update_irq(v); - do { intack = hvm_vcpu_has_pending_irq(v); if ( likely(intack.source == hvm_intsrc_none) ) @@ -219,7 +217,6 @@ void svm_intr_assist(void) { HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0); svm_inject_extint(v, intack.vector); - pt_intr_post(v, intack); } /* Is there another IRQ to queue up behind this one? */ diff --git a/xen/arch/x86/hvm/vmx/intr.c b/xen/arch/x86/hvm/vmx/intr.c index 80bfbb47878..3fcc7073db2 100644 --- a/xen/arch/x86/hvm/vmx/intr.c +++ b/xen/arch/x86/hvm/vmx/intr.c @@ -203,7 +203,6 @@ static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack) { /* for now, duplicate the ack path in vmx_intr_assist */ hvm_vcpu_ack_pending_irq(v, intack); - pt_intr_post(v, intack); intack = hvm_vcpu_has_pending_irq(v); if ( unlikely(intack.source != hvm_intsrc_none) ) @@ -242,7 +241,6 @@ void vmx_intr_assist(void) struct vcpu *v = current; unsigned int tpr_threshold = 0; enum hvm_intblk intblk; - int pt_vector; /* Block event injection when single step with MTF. */ if ( unlikely(v->arch.hvm.single_step) ) @@ -263,8 +261,6 @@ void vmx_intr_assist(void) #endif /* Crank the handle on interrupt state. */ - pt_vector = pt_update_irq(v); - do { unsigned long intr_info; @@ -337,58 +333,6 @@ void vmx_intr_assist(void) { unsigned long status; - /* - * intack.vector is the highest priority vector. So we set eoi_exit_bitmap - * for intack.vector - give a chance to post periodic time interrupts when - * periodic time interrupts become the highest one - */ - if ( pt_vector != -1 ) - { -#ifndef NDEBUG - /* - * We assert that intack.vector is the highest priority vector for - * only an interrupt from vlapic can reach this point and the - * highest vector is chosen in hvm_vcpu_has_pending_irq(). - * But, in fact, the assertion failed sometimes. It is suspected - * that PIR is not synced to vIRR which makes pt_vector is left in - * PIR. In order to verify this suspicion, dump some information - * when the assertion fails. - */ - if ( unlikely(intack.vector < pt_vector) ) - { - const struct vlapic *vlapic; - const struct pi_desc *pi_desc; - const uint32_t *word; - unsigned int i; - - printk(XENLOG_ERR "%pv: intack: %u:%02x pt: %02x\n", - current, intack.source, intack.vector, pt_vector); - - vlapic = vcpu_vlapic(v); - if ( vlapic && vlapic->regs ) - { - word = (const void *)&vlapic->regs->data[APIC_IRR]; - printk(XENLOG_ERR "vIRR:"); - for ( i = X86_NR_VECTORS / 32; i-- ; ) - printk(" %08x", word[i*4]); - printk("\n"); - } - - pi_desc = &v->arch.hvm.vmx.pi_desc; - if ( pi_desc ) - { - word = (const void *)&pi_desc->pir; - printk(XENLOG_ERR " PIR:"); - for ( i = X86_NR_VECTORS / 32; i-- ; ) - printk(" %08x", word[i]); - printk("\n"); - } - } -#endif - ASSERT(intack.vector >= pt_vector); - vmx_set_eoi_exit_bitmap(v, intack.vector); - } - /* we need update the RVI field */ __vmread(GUEST_INTR_STATUS, &status); status &= ~VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK; @@ -397,14 +341,11 @@ void vmx_intr_assist(void) __vmwrite(GUEST_INTR_STATUS, status); vmx_sync_exit_bitmap(v); - - pt_intr_post(v, intack); } else { HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0); vmx_inject_extint(intack.vector, intack.source); - pt_intr_post(v, intack); } /* Is there another IRQ to queue up behind this one? */ diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c index 4c2afe2e915..f951cd95bcf 100644 --- a/xen/arch/x86/hvm/vpt.c +++ b/xen/arch/x86/hvm/vpt.c @@ -27,6 +27,8 @@ #define mode_is(d, name) \ ((d)->arch.hvm.params[HVM_PARAM_TIMER_MODE] == HVMPTM_##name) +static bool inject_interrupt(struct periodic_time *pt); + void hvm_init_guest_time(struct domain *d) { struct pl_time *pl = d->arch.hvm.pl_time; @@ -76,35 +78,6 @@ void hvm_set_guest_time(struct vcpu *v, u64 guest_time) } } -static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src) -{ - struct vcpu *v = pt->vcpu; - unsigned int gsi, isa_irq; - int vector; - - if ( pt->source == PTSRC_lapic ) - return pt->irq; - - isa_irq = pt->irq; - - if ( src == hvm_intsrc_pic ) - return (v->domain->arch.hvm.vpic[isa_irq >> 3].irq_base - + (isa_irq & 7)); - - ASSERT(src == hvm_intsrc_lapic); - gsi = pt->source == PTSRC_isa ? hvm_isa_irq_to_gsi(isa_irq) : pt->irq; - vector = vioapic_get_vector(v->domain, gsi); - if ( vector < 0 ) - { - dprintk(XENLOG_WARNING, "d%u: invalid GSI (%u) for platform timer\n", - v->domain->domain_id, gsi); - domain_crash(v->domain); - return -1; - } - - return vector; -} - static int pt_irq_masked(struct periodic_time *pt) { struct vcpu *v = pt->vcpu; @@ -247,34 +220,14 @@ void pt_restore_timer(struct vcpu *v) pt_vcpu_lock(v); list_for_each_entry ( pt, head, list ) - { if ( pt->pending_intr_nr == 0 ) - { - pt_process_missed_ticks(pt); set_timer(&pt->timer, pt->scheduled); - } - } pt_thaw_time(v); pt_vcpu_unlock(v); } -static void pt_timer_fn(void *data) -{ - struct periodic_time *pt = data; - - pt_lock(pt); - - pt->pending_intr_nr++; - pt->scheduled += pt->period; - pt->do_not_freeze = 0; - - vcpu_kick(pt->vcpu); - - pt_unlock(pt); -} - static void pt_irq_fired(struct vcpu *v, struct periodic_time *pt) { pt->irq_issued = false; @@ -285,189 +238,144 @@ static void pt_irq_fired(struct vcpu *v, struct periodic_time *pt) list_del(&pt->list); pt->on_list = false; pt->pending_intr_nr = 0; + + return; } - else if ( mode_is(v->domain, one_missed_tick_pending) || - mode_is(v->domain, no_missed_ticks_pending) ) + + if ( mode_is(v->domain, one_missed_tick_pending) || + mode_is(v->domain, no_missed_ticks_pending) ) { - pt->last_plt_gtime = hvm_get_guest_time(v); pt_process_missed_ticks(pt); pt->pending_intr_nr = 0; /* 'collapse' all missed ticks */ + } + else if ( !pt->pending_intr_nr ) + pt_process_missed_ticks(pt); + + if ( !pt->pending_intr_nr ) set_timer(&pt->timer, pt->scheduled); +} + +static void pt_timer_fn(void *data) +{ + struct periodic_time *pt = data; + struct vcpu *v; + time_cb *cb = NULL; + void *cb_priv; + unsigned int irq; + + pt_lock(pt); + + v = pt->vcpu; + irq = pt->irq; + + if ( inject_interrupt(pt) ) + { + pt->scheduled += pt->period; + pt->do_not_freeze = 0; + cb = pt->cb; + cb_priv = pt->priv; } else { - pt->last_plt_gtime += pt->period; - if ( --pt->pending_intr_nr == 0 ) - { - pt_process_missed_ticks(pt); - if ( pt->pending_intr_nr == 0 ) - set_timer(&pt->timer, pt->scheduled); - } + /* Masked. */ + if ( pt->on_list ) + list_del(&pt->list); + pt->on_list = false; + pt->pending_intr_nr++; } - if ( mode_is(v->domain, delay_for_missed_ticks) && - (hvm_get_guest_time(v) < pt->last_plt_gtime) ) - hvm_set_guest_time(v, pt->last_plt_gtime); + pt_unlock(pt); + + if ( cb ) + cb(v, cb_priv); } -int pt_update_irq(struct vcpu *v) +/* + * The same callback is shared between LAPIC and PIC/IO-APIC based timers, as + * we ignore the first parameter that's different between them. + */ +static void eoi_callback(unsigned int unused, void *data) { - struct list_head *head = &v->arch.hvm.tm_list; - struct periodic_time *pt, *temp, *earliest_pt; - uint64_t max_lag; - int irq, pt_vector = -1; - bool level; + struct periodic_time *pt = data; + struct vcpu *v; + time_cb *cb = NULL; + void *cb_priv; - pt_vcpu_lock(v); + pt_lock(pt); - earliest_pt = NULL; - max_lag = -1ULL; - list_for_each_entry_safe ( pt, temp, head, list ) + pt_irq_fired(pt->vcpu, pt); + if ( pt->pending_intr_nr ) { - if ( pt->pending_intr_nr ) + if ( inject_interrupt(pt) ) + { + pt->pending_intr_nr--; + cb = pt->cb; + cb_priv = pt->priv; + v = pt->vcpu; + } + else { - /* RTC code takes care of disabling the timer itself. */ - if ( (pt->irq != RTC_IRQ || !pt->priv) && pt_irq_masked(pt) && - /* Level interrupts should be asserted even if masked. */ - !pt->level ) - { - /* suspend timer emulation */ + /* Masked. */ + if ( pt->on_list ) list_del(&pt->list); - pt->on_list = 0; - } - else - { - if ( (pt->last_plt_gtime + pt->period) < max_lag ) - { - max_lag = pt->last_plt_gtime + pt->period; - earliest_pt = pt; - } - } + pt->on_list = false; } } - if ( earliest_pt == NULL ) - { - pt_vcpu_unlock(v); - return -1; - } + pt_unlock(pt); - earliest_pt->irq_issued = 1; - irq = earliest_pt->irq; - level = earliest_pt->level; + if ( cb ) + cb(v, cb_priv); +} - pt_vcpu_unlock(v); +static bool inject_interrupt(struct periodic_time *pt) +{ + struct vcpu *v = pt->vcpu; + struct domain *d = v->domain; + unsigned int irq = pt->irq; - switch ( earliest_pt->source ) + if ( pt_irq_masked(pt) ) + return false; + + switch ( pt->source ) { case PTSRC_lapic: - /* - * If periodic timer interrupt is handled by lapic, its vector in - * IRR is returned and used to set eoi_exit_bitmap for virtual - * interrupt delivery case. Otherwise return -1 to do nothing. - */ - vlapic_set_irq(vcpu_vlapic(v), irq, 0); - pt_vector = irq; + vlapic_set_irq_callback(vcpu_vlapic(v), pt->irq, 0, eoi_callback, pt); break; case PTSRC_isa: - hvm_isa_irq_deassert(v->domain, irq); + hvm_isa_irq_deassert(d, irq); if ( platform_legacy_irq(irq) && vlapic_accept_pic_intr(v) && - v->domain->arch.hvm.vpic[irq >> 3].int_output ) - hvm_isa_irq_assert(v->domain, irq, NULL); + d->arch.hvm.vpic[irq >> 3].int_output ) + hvm_isa_irq_assert(d, irq, NULL); else - { - pt_vector = hvm_isa_irq_assert(v->domain, irq, vioapic_get_vector); - /* - * hvm_isa_irq_assert may not set the corresponding bit in vIRR - * when mask field of IOAPIC RTE is set. Check it again. - */ - if ( pt_vector < 0 || !vlapic_test_irq(vcpu_vlapic(v), pt_vector) ) - pt_vector = -1; - } + hvm_isa_irq_assert(d, irq, vioapic_get_vector); break; case PTSRC_ioapic: - pt_vector = hvm_ioapic_assert(v->domain, irq, level); - if ( pt_vector < 0 || !vlapic_test_irq(vcpu_vlapic(v), pt_vector) ) - { - pt_vector = -1; - if ( level ) - { - /* - * Level interrupts are always asserted because the pin assert - * count is incremented regardless of whether the pin is masked - * or the vector latched in IRR, so also execute the callback - * associated with the timer. - */ - time_cb *cb = NULL; - void *cb_priv = NULL; - - pt_vcpu_lock(v); - /* Make sure the timer is still on the list. */ - list_for_each_entry ( pt, &v->arch.hvm.tm_list, list ) - if ( pt == earliest_pt ) - { - pt_irq_fired(v, pt); - cb = pt->cb; - cb_priv = pt->priv; - break; - } - pt_vcpu_unlock(v); - - if ( cb != NULL ) - cb(v, cb_priv); - } - } + hvm_ioapic_assert(d, irq, pt->level); break; } - return pt_vector; -} - -static struct periodic_time *is_pt_irq( - struct vcpu *v, struct hvm_intack intack) -{ - struct list_head *head = &v->arch.hvm.tm_list; - struct periodic_time *pt; - - list_for_each_entry ( pt, head, list ) + switch ( d->arch.hvm.params[HVM_PARAM_TIMER_MODE] ) { - if ( pt->pending_intr_nr && pt->irq_issued && - (intack.vector == pt_irq_vector(pt, intack.source)) ) - return pt; - } - - return NULL; -} - -void pt_intr_post(struct vcpu *v, struct hvm_intack intack) -{ - struct periodic_time *pt; - time_cb *cb; - void *cb_priv; - - if ( intack.source == hvm_intsrc_vector ) - return; + case HVMPTM_one_missed_tick_pending: + case HVMPTM_no_missed_ticks_pending: + pt->last_plt_gtime = hvm_get_guest_time(v); + break; - pt_vcpu_lock(v); + case HVMPTM_delay_for_missed_ticks: + pt->last_plt_gtime += pt->period; + if ( hvm_get_guest_time(v) < pt->last_plt_gtime ) + hvm_set_guest_time(v, pt->last_plt_gtime); + break; - pt = is_pt_irq(v, intack); - if ( pt == NULL ) - { - pt_vcpu_unlock(v); - return; + default: + pt->last_plt_gtime += pt->period; + break; } - pt_irq_fired(v, pt); - - cb = pt->cb; - cb_priv = pt->priv; - - pt_vcpu_unlock(v); - - if ( cb != NULL ) - cb(v, cb_priv); + return true; } void pt_migrate(struct vcpu *v) @@ -543,6 +451,24 @@ void create_periodic_time( pt->cb = cb; pt->priv = data; + switch ( pt->source ) + { + int rc; + + case PTSRC_isa: + irq = hvm_isa_irq_to_gsi(irq); + /* fallthrough */ + case PTSRC_ioapic: + pt->eoi_cb.callback = eoi_callback; + pt->eoi_cb.data = pt; + rc = hvm_gsi_register_callback(v->domain, irq, &pt->eoi_cb); + if ( rc ) + gdprintk(XENLOG_WARNING, + "unable to register callback for timer GSI %u source %u: %d\n", + irq, pt->source, rc); + break; + } + pt->on_list = 1; list_add(&pt->list, &v->arch.hvm.tm_list); @@ -554,6 +480,8 @@ void create_periodic_time( void destroy_periodic_time(struct periodic_time *pt) { + unsigned int gsi; + /* Was this structure previously initialised by create_periodic_time()? */ if ( pt->vcpu == NULL ) return; @@ -563,6 +491,17 @@ void destroy_periodic_time(struct periodic_time *pt) list_del(&pt->list); pt->on_list = 0; pt->pending_intr_nr = 0; + + gsi = pt->irq; + switch ( pt->source ) + { + case PTSRC_isa: + gsi = hvm_isa_irq_to_gsi(pt->irq); + /* fallthrough */ + case PTSRC_ioapic: + hvm_gsi_unregister_callback(pt->vcpu->domain, gsi, &pt->eoi_cb); + break; + } pt_unlock(pt); /* @@ -617,20 +556,29 @@ void pt_adjust_global_vcpu_target(struct vcpu *v) write_unlock(&pl_time->vhpet.lock); } - static void pt_resume(struct periodic_time *pt) { + struct vcpu *v; + time_cb *cb = NULL; + void *cb_priv; + if ( pt->vcpu == NULL ) return; pt_lock(pt); - if ( pt->pending_intr_nr && !pt->on_list ) + if ( pt->pending_intr_nr && !pt->on_list && inject_interrupt(pt) ) { + pt->pending_intr_nr--; + cb = pt->cb; + cb_priv = pt->priv; + v = pt->vcpu; pt->on_list = 1; list_add(&pt->list, &pt->vcpu->arch.hvm.tm_list); - vcpu_kick(pt->vcpu); } pt_unlock(pt); + + if ( cb ) + cb(v, cb_priv); } void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt) diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h index 39d26cbda49..9440fe4ac7d 100644 --- a/xen/include/asm-x86/hvm/vpt.h +++ b/xen/include/asm-x86/hvm/vpt.h @@ -23,6 +23,7 @@ #include #include #include +#include /* * Abstract layer of periodic time, one short time. @@ -50,6 +51,7 @@ struct periodic_time { struct timer timer; /* ac_timer */ time_cb *cb; void *priv; /* point back to platform time source */ + struct hvm_gsi_eoi_callback eoi_cb; /* EOI callback registration data */ }; @@ -145,9 +147,6 @@ struct pl_time { /* platform time */ void pt_save_timer(struct vcpu *v); void pt_restore_timer(struct vcpu *v); -int pt_update_irq(struct vcpu *v); -struct hvm_intack; -void pt_intr_post(struct vcpu *v, struct hvm_intack intack); void pt_migrate(struct vcpu *v); void pt_adjust_global_vcpu_target(struct vcpu *v); From patchwork Wed Mar 31 10:33:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58C10C433DB for ; Wed, 31 Mar 2021 10:36:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D9CAB61582 for ; Wed, 31 Mar 2021 10:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9CAB61582 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103858.198115 (Exim 4.92) (envelope-from ) id 1lRYDJ-0005Ji-1z; Wed, 31 Mar 2021 10:36:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103858.198115; Wed, 31 Mar 2021 10:36:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDI-0005Jb-Ui; Wed, 31 Mar 2021 10:36:40 +0000 Received: by outflank-mailman (input) for mailman id 103858; Wed, 31 Mar 2021 10:36:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDH-0005Ed-JG for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:39 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 440c7728-2050-4477-a6dd-05bb39e4a66f; Wed, 31 Mar 2021 10:36:38 +0000 (UTC) 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: 440c7728-2050-4477-a6dd-05bb39e4a66f DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617186997; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=B3R84wGa0btRIL/3aNgrKfpGpevLyFpwyXFTHJnsMJ0=; b=SSPNJfXwG/1rMAzA3rau21NMjcro7nbt87SNDxUR9G3MaUUumcRUgA11 6q0Qo2xAbo+qxmamXchS9OpoyJYRCeK1dbJt/YK2It3EfltWaNhFBO9Lr tmrdZIT1zlvOv1PfDX4V3WE3ZUnAaZwZjR2QyBzZrKaV5+nf6lu3ZkCdG 0=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: J0+egh/HB9w0uExws+9FQpNDWGM/17eI9U5UUsZUD9o912kloBjPpsMtSfje76GBCX7Yrgk3u9 empouI3GLEc1z/GUM1CYrm0Em4q9ezUxPH78HFRkFllkEIpbH7N3kf36HLnrLHNhtKUr2Yqedn csfK+Klyqe5W25YumqNessRWB4pIcWXOTrGQrHYPjB+TW/Np4ekU3Ph0I5NGvx48JS9LK87X6S Rc85jLJu4Pz33RV5CR1Ho+vWhBUerwtH2wyrl5wmOQR2twHnhLKOumVJyhNuAa6ctNu61aoSAl XEE= X-SBRS: 5.2 X-MesageID: 40526885 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:DHm5Kq4VNS/c6S4p4APXwU2EI+orLtY04lQ7vn1ZYSd+NuSFis Gjm+ka3xfoiDAXHEotg8yEJbPoexzh3LZPy800Ma25VAfr/FGpIoZr8Jf4z1TbdxHW3tV2kZ 1te60WMrDNJHBnkMf35xS5Gd48wN+BtJuln/va0m0Fd2BXQotLhj0JbjqzOEtwWQVAGN4FD5 Ka/MVKvH6Nfn4QY8S9CBA+LpT+jvfMk4/rZgNDOg4/5GC1/E6VwZPZMzzd5BcRVDtT3awvmF KqryXV7riu2svLrCP0+HTU6/1t6bnc4/tFQPeBk80Ebgjr4zzYH7hJf52nkHQLrPq06FAs+e O80ysIG8ho8XveciWUjHLWqnDd+Q0j4XPj1lOU6EGLyaeSJENYerh8rLlUfRfD500rsMsU6t Mw40uju4dKFhSFpSzh5rHzJmBXv3Cpqnkvm/N7tQ05baIibtZq3Oki1XIQOpIBECXm0ZsgAe ljAerNjcwmD2+yXjT3uHJiz8erWWl2NhCaQlIassjQ6DROmmtlpnFoiPA3rzMlztYQWpNE7+ PLPuBBk6xPdNYfaeZYCP0aScW6J2TRSXv3QS2vCGWiMJtCF2PGqpbx7rlwzvqtYoY0wJw7n4 mEeE9EtEYpEnieSfGm7dluyFTgUW+9VTPixoV1/J5ioIDxQ7LtLGmqVE0uqc29uP8Sa/erGs qbCdZzObvOPGHuEYFG00nVQJ9JM0QTV8UTp5IVQFSLjsXXKpD7l+DSffrJTYCdUwoMayfaOD 8uTTLzLMJP4gSAQXnjmiXcXHvrZwje8PtLYe3n1tlW7LJIGpxHswATh1j8zNqMMyd+vqs/e1 Y7BLvml6i8tFSn5Gqg1RQsBjNtSmJupJnwWXJDogEHd2nud6wYhtmZcWdOmFyKOwF4VMGTNA JEvVx49eaWIvWrtG4fIuPiFljfo2oYpXqMQZtZsLaE/93ZdpQxCYtjfrdwGwXNHxlcgh1rt2 9HVQ8BSibkZ3DToJTgqKZRKPDUdtF6jgvuC9VTs2jjuUKVotxqemEWRAe0UcmcgR8nQh1dgl EZyd5ZvJOw3RKUbUcviuUxN1NBLECaGqhPAgi+aIJIobzzYw1rQWCWhTuVtgErdgPRhjYvr1 2kCRfRVeDAA1JbtHwd6Krs/V9uXki2fk57aBlBwMZAPFWDnkw2/f6AZ6K13WfUV0ALxfsFNi rZJREIJBl1+tyx3BmJuTqLGHk83K8yNujFALlLScCU5lqdbKmz0Y0WFf5d+5hocO30uugQSO SFZku7Kij7B+5B4X3iml8VfA1P7F8qnvPj1Ee7sCyW3HsjDeHTJ1ojbbcBON2Y53XlQfHN8J gRt6NAgcKAdkHKLviBwuXrShQGDDX5i2u/VfspppBZprhajso6I7DrFR/zkEha1xA/JvrunE wQQK5H8KnMU7UfCvA6SmZ8xB4Vj9yBI0sgjxzuDsI/dV8riWXHP9nh2cu+lZMfRmmIpA79Ij CkglVg1saAeyuIzrgBDa0sZUxQdUgn8XxnldnyPbH4OUGPd+tZ+kC9PWL4WLhBSLKdEbFVih ph+dmHk6u2cCX/sTqg8AdTE+Zr82y9R9m1Dx/JMelU88aiMVDJu5CU2qeI/X7KYAr+TV8Zi4 1DfVERacoGqgBKtvxJ7gGCDortokwklFNC5ypAjVCF4Pn+3Fvm X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40526885" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zzc/wNQ3ljeOR4eZhtwJUbxP/AuLct8xKDkONao4O3aXc13WRZsA0D+11QY0XVwyETlmrB9xLOJWTkEyjDyCR82d+lqkKYEjdoWfe3RgDnezp/EB2AeN4bcqboWztzBht23dWz25DxlD5huxZMvHImjkiEb1NK8zDS0LCYK/pP2hPKk6jEQv0dhi6k7BPvQxTJ9XJvMQcXbvdhQRvfSkR3noZ7XnSPz3bRYDscUJTGYcY+EuOHCTeoMv8VLsMtpmmcpehtS7CWswcaJ1L7ziJg3FBBdubHVFNb4JeNY86cQ7Wuuw6gc6EbVv6yAf8DgyowlR9orFxiQFSHAXpTnFjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OBYI1lpn/Fj2wAf8tHHymIobOKG3y0f6hpA3NmNveyE=; b=aleQpKvS2SO0DBknfMZ5EkFTOzRlnwfF4sVpIUSegYCJPNguTymaw+md6/3URuG5wrsIJI70A/b17FxkrAFgJxMJZ6o1ZQDpCQiWaReaPHr3NbLrm72EVJ4PaKkIujV8J14EKYEx78ZihJ6fl25ysukFfhH6Ac5eFGx+riTI/5kI9WVXYEqRTp3UycursdyhV50dXDATpms6FNPjJs3vg6kAHMP+dcj/TrLLBZGQ4LaQR1CSYaiRRGsbuLVX7hctI+dij5n+swGBGnfaTaBWBxKjm94Rb2ADwplkcY6KgATlLAHWTVDTVVM36m60H3hhu7rdo8Gj9ToHznQ3FNfymw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OBYI1lpn/Fj2wAf8tHHymIobOKG3y0f6hpA3NmNveyE=; b=ApRSLVEpeO1RkHrFz+izAix7NlukknuZu9a3BB/Ez1F1DNZa4GFynfHttRxfcelcnMjKDCYuBg8G00Ndm9BvNRZyXwVwIzZ4mYbJpms66cgbg+7PqcjCNeZg0Cp+mJfN/wnNu4jF9U+waTv1oXdZHVrGDGrdyOIBB3TENd6idhY= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 10/11] x86/vpt: remove vPT timers per-vCPU lists Date: Wed, 31 Mar 2021 12:33:02 +0200 Message-ID: <20210331103303.79705-11-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0079.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::19) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aed7e27a-8a5d-4e4e-d2fd-08d8f430db10 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0PS4fuAgedwJDFLy+NSQUDq58ytXpZ/X9mmNtwnv86dlymuEghiUCFGgNmNGw4OUjJZ4RTa3V04BCz8U2NiyYUX4yFAqP4Rs6GkVLZAvk3yORj8wNqXhRvV+UuYaTT0x7FmpWRgqR30jivksDhLJkvM7C+iVGBWyylW4jcKDqwSvbfwU8CQlbFGp8LVQluyXNXbioGub5L1aBr9aP79R3Uoc4VuY8QrhUUkbuiiPSD1LXk7ilAUX9RjYDUTyt5VNZSZVgdIyGSdwyJTDU1wNbtQW254peqBIV3gKyVMzDiB6Aoumr6jYROKtckAG5ktasx61uvmSHYvTiohJc6l93bR6DOHXN3WEgw0DE9ZE7r5aaZnzgQs4MdCGQZZAAZ7z/9ZQq5YiP4DRU0jd9b/Nb16Cq7P17b+LhGzOrNyQmLs+7SMqttlkTkIZPMLbhT0V7ZyaJ0wO2t7aa79EjAb+k6nNXr9B4Fw4FsceRYs0Mi+MzwijsmRFssVgiRMmdlXcGK8yZlglKog3uMGw+Vr9tbjT/OP+Dnr3oWf4F2Daopi93bCz5lLMIfC0TmZrFlUdBmQ8RyenQHJpBcWO8UAjsmVJ8f7vx+GvXr2dMm5Vb20WToYvDFcyIg7SbUqUCHQURhRyxO7WodsPLUQhSujGHRtq5KIQnQ/4W4i0FyJ4eq0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(30864003)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?W6/OGnRxrYWBBQVOX9JqLTUWy3k0Kn?= =?utf-8?q?HxozaMcqG9MLlRDw9FB4SrwQwhaatE+k9KD/ScOOJ6evi9P3/JwE4JxzfzMIzd445?= =?utf-8?q?dOqEzuebjCbUmlaG6UoNkFcmcHHFM8gEInHPSLyC70/RY28D4JqoyAAfL2wykQx7U?= =?utf-8?q?2dg2Z/PNLEYRpi9wWUDX31swN5ty9BvvZqhV4jefGJP7kEKiQgbZ8mKXAccLi+oDT?= =?utf-8?q?9n1ipKXcnuNzjz+qzO0bhOnFNkQryHDzoRD8GvcwohcfVcH8jdJZBdFe/dJ5/kfWN?= =?utf-8?q?vgdBKHQoUxSw40wixS/e2WBCC78iZnlzU/RnG55MimBB71fNQIgMFCjs6BOXLXZHC?= =?utf-8?q?UhkyzNOI0W+Xf+fIyiiecI7ic/N2t7vc+EcQr4dq1qhQtjrJrUCbvWLLWY6ig++yA?= =?utf-8?q?4lg53bMcUg2lSe8lcNKULgpnrbMsBM+r+SNggTpVv4gKZphpLgdIKglNhscg3PP45?= =?utf-8?q?zH+4iH+MHPq555YKm6Misz6YyUHGhX2r2BrRfU+MDsebJ05izT2sHX1J44sPtiBeY?= =?utf-8?q?Vr4z70V4zq33lhWUCz07kzMzoTSG2q8Z0bcP4NImsHyMngIoJFFBfEiCzrMDu1ozS?= =?utf-8?q?mcAIC6JFgMnSNBAGH0wDbys6tom9Xd00iB9SiVznEqvR4tfVFnejFCKUnU5Sdym8Z?= =?utf-8?q?dIx0Aahhyu560QysLN9G9JFgWS2193vwEgsCdv9djOro71G9kIKLzuIhZBKBQTzDL?= =?utf-8?q?HFQo+BdEOjL1kXIWJf42gYaz8PM0LLT3zQc7k8DGukNptvVdIKBZUP6lbCuHD+7+7?= =?utf-8?q?V0o0RBU52FtiVBx8iFRu2j+ravhvtLafIG7kPBW1sZmqFfZc+Ay2RWTh9cbTYeb+K?= =?utf-8?q?tee7FUGUHr5zTEiS9xVHzhGoppB2dbC/fHMdcNJ/g+VSDw//gBN8/7GjPiHrzCd9k?= =?utf-8?q?XLcvcBM6VFAbKuWU6VpRmJRz+8n0/+iANxKolMH7SQs3HjhEKtb82vjxv+858KDND?= =?utf-8?q?efoQGd/OVH+fI8xEwFvGo2aL8+DwroSW7r2fylod0sJsfzdlhyO5Q2Fyx41rbd6yP?= =?utf-8?q?6gRGKvIkQL789GHrJvTwSzzt3cqmibkGDueT4Km9t7AJHP7d9lhXNikBOjjoGMgXt?= =?utf-8?q?uP57w7IVuDhJV0vFcMhAYNDmYZ5QaG+yfCmXGeirXaCwarPsneQp6a2JJtqTeloYq?= =?utf-8?q?Jrle3liXFlDtLnZMf7vOBzypSX1aXDj+jBGjiIhtniHNFQR6TesMDMOHI9APWMcHR?= =?utf-8?q?bMl2flsr15Jdl2t5kYt1PZJZ2Kch42ULoyPInozYYRHzQmSsUE+1XoBjzLO6P7yG9?= =?utf-8?q?0Mh2+Vi2+rcMtO?= X-MS-Exchange-CrossTenant-Network-Message-Id: aed7e27a-8a5d-4e4e-d2fd-08d8f430db10 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:34.4831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: b9TtQBuLChHUbdsPZotUwQ+IHZ++3MlAJI5FN7ZTQ+Ki6MDfd60FE8FBxTCNe4X10V++9JGzVeWMo+vXE8iMYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com No longer add vPT timers to lists on specific vCPUs, since there's no need anymore to check if timer interrupts have been injected on return to HVM guest. Such change allows to get rid of virtual timers vCPU migration, and also cleanup some of the virtual timers fields that are no longer required. The model is also slightly different now in that timers are not stopped when a vCPU is de-scheduled. Such timers will continue running, and when triggered the function will try to inject the corresponding interrupt to the guest (which might be different than the currently running one). Note that the timer triggering when the guest is no longer running can only happen once, as the timer callback will not reset the interrupt to fire again. Such resetting if required will be done by the EOI callback. Since virtual timers are no longer added to per-VCPU lists when active a new 'masked' field is added to the structure, to signal whether a timer has it's interrupt source currently masked. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Remove pt_{save/restore}_timer and instead use pt_{freeze/thaw}_time. - Remove the introduction of the 'masked' field, it's not needed. - Rework pt_active to use timer_is_active. Changes since v1: - New in this version. --- xen/arch/x86/domain.c | 4 +- xen/arch/x86/hvm/hvm.c | 4 +- xen/arch/x86/hvm/vlapic.c | 1 - xen/arch/x86/hvm/vpt.c | 174 ++++----------------------------- xen/include/asm-x86/hvm/vcpu.h | 3 +- xen/include/asm-x86/hvm/vpt.h | 12 +-- 6 files changed, 27 insertions(+), 171 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index b2127298800..a711ff2814a 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2014,8 +2014,8 @@ void context_switch(struct vcpu *prev, struct vcpu *next) vpmu_switch_from(prev); np2m_schedule(NP2M_SCHEDLE_OUT); - if ( is_hvm_domain(prevd) && !list_empty(&prev->arch.hvm.tm_list) ) - pt_save_timer(prev); + if ( is_hvm_domain(prevd) ) + pt_freeze_time(prev); local_irq_disable(); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 0279014e66e..3a72da67ef2 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -489,7 +489,6 @@ void hvm_set_info_guest(struct vcpu *v) void hvm_migrate_timers(struct vcpu *v) { rtc_migrate_timers(v); - pt_migrate(v); } void hvm_migrate_pirq(struct hvm_pirq_dpci *pirq_dpci, const struct vcpu *v) @@ -544,7 +543,7 @@ void hvm_do_resume(struct vcpu *v) { check_wakeup_from_wait(); - pt_restore_timer(v); + pt_thaw_time(v); if ( !vcpu_ioreq_handle_completion(v) ) return; @@ -1558,7 +1557,6 @@ int hvm_vcpu_initialise(struct vcpu *v) hvm_asid_flush_vcpu(v); spin_lock_init(&v->arch.hvm.tm_lock); - INIT_LIST_HEAD(&v->arch.hvm.tm_list); rc = hvm_vcpu_cacheattr_init(v); /* teardown: vcpu_cacheattr_destroy */ if ( rc != 0 ) diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 63fa3780767..8091b6d8925 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1339,7 +1339,6 @@ void vlapic_adjust_i8259_target(struct domain *d) if ( d->arch.hvm.i8259_target == v ) return; d->arch.hvm.i8259_target = v; - pt_adjust_global_vcpu_target(v); } int vlapic_has_pending_irq(struct vcpu *v) diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c index f951cd95bcf..84d49c1b25c 100644 --- a/xen/arch/x86/hvm/vpt.c +++ b/xen/arch/x86/hvm/vpt.c @@ -126,18 +126,6 @@ static int pt_irq_masked(struct periodic_time *pt) return 1; } -static void pt_vcpu_lock(struct vcpu *v) -{ - read_lock(&v->domain->arch.hvm.pl_time->pt_migrate); - spin_lock(&v->arch.hvm.tm_lock); -} - -static void pt_vcpu_unlock(struct vcpu *v) -{ - spin_unlock(&v->arch.hvm.tm_lock); - read_unlock(&v->domain->arch.hvm.pl_time->pt_migrate); -} - static void pt_lock(struct periodic_time *pt) { /* @@ -151,7 +139,8 @@ static void pt_lock(struct periodic_time *pt) static void pt_unlock(struct periodic_time *pt) { - pt_vcpu_unlock(pt->vcpu); + spin_unlock(&pt->vcpu->arch.hvm.tm_lock); + read_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate); } static void pt_process_missed_ticks(struct periodic_time *pt) @@ -166,14 +155,12 @@ static void pt_process_missed_ticks(struct periodic_time *pt) return; missed_ticks = missed_ticks / (s_time_t) pt->period + 1; - if ( mode_is(pt->vcpu->domain, no_missed_ticks_pending) ) - pt->do_not_freeze = !pt->pending_intr_nr; - else + if ( !mode_is(pt->vcpu->domain, no_missed_ticks_pending) ) pt->pending_intr_nr += missed_ticks; pt->scheduled += missed_ticks * pt->period; } -static void pt_freeze_time(struct vcpu *v) +void pt_freeze_time(struct vcpu *v) { if ( !mode_is(v->domain, delay_for_missed_ticks) ) return; @@ -181,7 +168,7 @@ static void pt_freeze_time(struct vcpu *v) v->arch.hvm.guest_time = hvm_get_guest_time(v); } -static void pt_thaw_time(struct vcpu *v) +void pt_thaw_time(struct vcpu *v) { if ( !mode_is(v->domain, delay_for_missed_ticks) ) return; @@ -193,52 +180,11 @@ static void pt_thaw_time(struct vcpu *v) v->arch.hvm.guest_time = 0; } -void pt_save_timer(struct vcpu *v) -{ - struct list_head *head = &v->arch.hvm.tm_list; - struct periodic_time *pt; - - if ( v->pause_flags & VPF_blocked ) - return; - - pt_vcpu_lock(v); - - list_for_each_entry ( pt, head, list ) - if ( !pt->do_not_freeze ) - stop_timer(&pt->timer); - - pt_freeze_time(v); - - pt_vcpu_unlock(v); -} - -void pt_restore_timer(struct vcpu *v) -{ - struct list_head *head = &v->arch.hvm.tm_list; - struct periodic_time *pt; - - pt_vcpu_lock(v); - - list_for_each_entry ( pt, head, list ) - if ( pt->pending_intr_nr == 0 ) - set_timer(&pt->timer, pt->scheduled); - - pt_thaw_time(v); - - pt_vcpu_unlock(v); -} - static void pt_irq_fired(struct vcpu *v, struct periodic_time *pt) { - pt->irq_issued = false; - if ( pt->one_shot ) { - if ( pt->on_list ) - list_del(&pt->list); - pt->on_list = false; pt->pending_intr_nr = 0; - return; } @@ -252,7 +198,11 @@ static void pt_irq_fired(struct vcpu *v, struct periodic_time *pt) pt_process_missed_ticks(pt); if ( !pt->pending_intr_nr ) + { + /* Make sure timer follows vCPU. */ + migrate_timer(&pt->timer, current->processor); set_timer(&pt->timer, pt->scheduled); + } } static void pt_timer_fn(void *data) @@ -268,21 +218,15 @@ static void pt_timer_fn(void *data) v = pt->vcpu; irq = pt->irq; - if ( inject_interrupt(pt) ) + pt->scheduled += pt->period; + + if ( !inject_interrupt(pt) ) + pt->pending_intr_nr++; + else { - pt->scheduled += pt->period; - pt->do_not_freeze = 0; cb = pt->cb; cb_priv = pt->priv; } - else - { - /* Masked. */ - if ( pt->on_list ) - list_del(&pt->list); - pt->on_list = false; - pt->pending_intr_nr++; - } pt_unlock(pt); @@ -304,22 +248,12 @@ static void eoi_callback(unsigned int unused, void *data) pt_lock(pt); pt_irq_fired(pt->vcpu, pt); - if ( pt->pending_intr_nr ) + if ( pt->pending_intr_nr && inject_interrupt(pt) ) { - if ( inject_interrupt(pt) ) - { - pt->pending_intr_nr--; - cb = pt->cb; - cb_priv = pt->priv; - v = pt->vcpu; - } - else - { - /* Masked. */ - if ( pt->on_list ) - list_del(&pt->list); - pt->on_list = false; - } + pt->pending_intr_nr--; + cb = pt->cb; + cb_priv = pt->priv; + v = pt->vcpu; } pt_unlock(pt); @@ -378,19 +312,6 @@ static bool inject_interrupt(struct periodic_time *pt) return true; } -void pt_migrate(struct vcpu *v) -{ - struct list_head *head = &v->arch.hvm.tm_list; - struct periodic_time *pt; - - pt_vcpu_lock(v); - - list_for_each_entry ( pt, head, list ) - migrate_timer(&pt->timer, v->processor); - - pt_vcpu_unlock(v); -} - void create_periodic_time( struct vcpu *v, struct periodic_time *pt, uint64_t delta, uint64_t period, uint8_t irq, time_cb *cb, void *data, bool level) @@ -410,8 +331,6 @@ void create_periodic_time( write_lock(&v->domain->arch.hvm.pl_time->pt_migrate); pt->pending_intr_nr = 0; - pt->do_not_freeze = 0; - pt->irq_issued = 0; /* Periodic timer must be at least 0.1ms. */ if ( (period < 100000) && period ) @@ -469,9 +388,6 @@ void create_periodic_time( break; } - pt->on_list = 1; - list_add(&pt->list, &v->arch.hvm.tm_list); - init_timer(&pt->timer, pt_timer_fn, pt, v->processor); set_timer(&pt->timer, pt->scheduled); @@ -487,9 +403,6 @@ void destroy_periodic_time(struct periodic_time *pt) return; pt_lock(pt); - if ( pt->on_list ) - list_del(&pt->list); - pt->on_list = 0; pt->pending_intr_nr = 0; gsi = pt->irq; @@ -511,51 +424,6 @@ void destroy_periodic_time(struct periodic_time *pt) kill_timer(&pt->timer); } -static void pt_adjust_vcpu(struct periodic_time *pt, struct vcpu *v) -{ - ASSERT(pt->source == PTSRC_isa || pt->source == PTSRC_ioapic); - - if ( pt->vcpu == NULL ) - return; - - write_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate); - pt->vcpu = v; - if ( pt->on_list ) - { - list_del(&pt->list); - list_add(&pt->list, &v->arch.hvm.tm_list); - migrate_timer(&pt->timer, v->processor); - } - write_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate); -} - -void pt_adjust_global_vcpu_target(struct vcpu *v) -{ - struct PITState *vpit; - struct pl_time *pl_time; - int i; - - if ( !v || !has_vpit(v->domain) ) - return; - - vpit = &v->domain->arch.vpit; - - spin_lock(&vpit->lock); - pt_adjust_vcpu(&vpit->pt0, v); - spin_unlock(&vpit->lock); - - pl_time = v->domain->arch.hvm.pl_time; - - spin_lock(&pl_time->vrtc.lock); - pt_adjust_vcpu(&pl_time->vrtc.pt, v); - spin_unlock(&pl_time->vrtc.lock); - - write_lock(&pl_time->vhpet.lock); - for ( i = 0; i < HPET_TIMER_NUM; i++ ) - pt_adjust_vcpu(&pl_time->vhpet.pt[i], v); - write_unlock(&pl_time->vhpet.lock); -} - static void pt_resume(struct periodic_time *pt) { struct vcpu *v; @@ -566,14 +434,12 @@ static void pt_resume(struct periodic_time *pt) return; pt_lock(pt); - if ( pt->pending_intr_nr && !pt->on_list && inject_interrupt(pt) ) + if ( pt->pending_intr_nr && inject_interrupt(pt) ) { pt->pending_intr_nr--; cb = pt->cb; cb_priv = pt->priv; v = pt->vcpu; - pt->on_list = 1; - list_add(&pt->list, &pt->vcpu->arch.hvm.tm_list); } pt_unlock(pt); diff --git a/xen/include/asm-x86/hvm/vcpu.h b/xen/include/asm-x86/hvm/vcpu.h index 8adf4555c2a..9a756964fb0 100644 --- a/xen/include/asm-x86/hvm/vcpu.h +++ b/xen/include/asm-x86/hvm/vcpu.h @@ -148,9 +148,8 @@ struct hvm_vcpu { s64 cache_tsc_offset; u64 guest_time; - /* Lock and list for virtual platform timers. */ + /* Lock for virtual platform timers. */ spinlock_t tm_lock; - struct list_head tm_list; bool flag_dr_dirty; bool debug_state_latch; diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h index 9440fe4ac7d..af04efa5e01 100644 --- a/xen/include/asm-x86/hvm/vpt.h +++ b/xen/include/asm-x86/hvm/vpt.h @@ -31,11 +31,7 @@ typedef void time_cb(struct vcpu *v, void *opaque); struct periodic_time { - struct list_head list; - bool on_list; bool one_shot; - bool do_not_freeze; - bool irq_issued; bool warned_timeout_too_short; bool level; #define PTSRC_isa 1 /* ISA time source */ @@ -145,11 +141,9 @@ struct pl_time { /* platform time */ struct domain *domain; }; -void pt_save_timer(struct vcpu *v); -void pt_restore_timer(struct vcpu *v); -void pt_migrate(struct vcpu *v); +void pt_freeze_time(struct vcpu *v); +void pt_thaw_time(struct vcpu *v); -void pt_adjust_global_vcpu_target(struct vcpu *v); #define pt_global_vcpu_target(d) \ (is_hvm_domain(d) && (d)->arch.hvm.i8259_target ? \ (d)->arch.hvm.i8259_target : \ @@ -158,7 +152,7 @@ void pt_adjust_global_vcpu_target(struct vcpu *v); void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt); /* Is given periodic timer active? */ -#define pt_active(pt) ((pt)->on_list || (pt)->pending_intr_nr) +#define pt_active(pt) ((pt)->pending_intr_nr || timer_is_active(&(pt)->timer)) /* * Create/destroy a periodic (or one-shot!) timer. From patchwork Wed Mar 31 10:33:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12175037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8D02C433C1 for ; Wed, 31 Mar 2021 10:36:57 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6693B60C3D for ; Wed, 31 Mar 2021 10:36:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6693B60C3D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.103861.198127 (Exim 4.92) (envelope-from ) id 1lRYDP-0005QP-Cz; Wed, 31 Mar 2021 10:36:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 103861.198127; Wed, 31 Mar 2021 10:36:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDP-0005QI-8g; Wed, 31 Mar 2021 10:36:47 +0000 Received: by outflank-mailman (input) for mailman id 103861; Wed, 31 Mar 2021 10:36:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lRYDN-0005P3-NK for xen-devel@lists.xenproject.org; Wed, 31 Mar 2021 10:36:45 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e8057e55-bac8-4d14-b16e-6e684cd096bf; Wed, 31 Mar 2021 10:36:44 +0000 (UTC) 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: e8057e55-bac8-4d14-b16e-6e684cd096bf DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1617187004; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=JPCmVO9asq4INCZJr57/0dCrCiXwQMJC6md2SxhVFUA=; b=c9zNBZqcsB2+0+gVHTEXdjt7yXbQZLT9gH+Gspal3Va/LVhX+Jjv9bic musVEHh5as9n4ZqQw+FLN6pb2pFWeasX5yWFYiqDPOuhBohBtxzneX5ev x+qFb7fFSiG4NxieZEK3W40KR5ii/KwEI6+JF8H3y3+/MQcqtheIASWbh Q=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: re6kwNWVYOTXd+BZWHE3Mnn33KcpCYvPJYP3KfhJe2Z85yyiXaDDrrVO843nBt9yiU2I8yU16T hg/8H8nDDO2aP7nA3YcqucSQSDrjg30z0UO6ex91pDDXmN13GEMU67vIXTYsc3cTYBvZrxhYAc j3Sltq+WLRB2BZRAOACqOV6qdeVvfKtEQSo1m3p6KDNBZ8mYzE6k2gc+EYoUi8LYBgGT3aleMX LZ+z1W6hHa8G66a1p1OGYEQwFoODkv3BCS301vsceJbwdw0gNZLy1UDyArZN+RDFUUB2/NDHGM hSM= X-SBRS: 5.2 X-MesageID: 40415700 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:RyErbq9TtTZ4PCIjgRJuk+ECdb1zdoIgy1knxilNYDRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsS9aFnb8oN45pRUAKe6UGDdyQ6VBaxBza+n+T3vHCXi6vVQvJ 0LT4FSAMD9ZGIUse/U+w+9euxP/PCi0ISFwdjT1G1sSwYCUdAD0y5cBhyAGkN7AClqbKBYKL Om6sBKpyWtdB0sB6zWOlA/U/XevNqOrZr6YHc9bCIP0hWEjj+j9dfBYnul9yoZOgkv/Z4StV Lrvia8zaWlvvG9xHbnphXuxqUTovTN4J9uAMSNj+IcNznjjB25Db4RJoGqjXQOj8yErHosjd nQszcsVv4Dl0/5TyWOjjbGnynmzTo05HfpxTaj8ATeiP28fh0WIY5lp+tiA3/kwntlhv5Q+u Z3+ljckJxtARbJjE3GlqD1fiAvrGWYiz4fi+IJ5kYvNrc2WftqgqE02lhaK5sEFDKS0vFdLM BeSPvR4/tbajqhHhbkl1gqxNStW0I6FQudTn4DvdSI0yNXkGoR9Tpg+PAi X-IronPort-AV: E=Sophos;i="5.81,293,1610427600"; d="scan'208";a="40415700" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FeoLPm0S04X22AEQ4NWEiE6YXTD7MgmfZVE+WmQ0XzFHcZGqRnQ+KIsOgaEmROPIo6+quiO622/eymc7Y/rgMjJrHaDNhVK8bkSogrIEAVeYP2/WzDySqfQM0NNp6EdTqqOd6h1lJ4iB/VD6flrqgvPiSZz4KAy00nSnpUGhSKtGiAOzScnt2/FrnbMbAx6ZHtybnLAzkCBU4AMADF+4pSOApop4WyS0BWlJ/KX34I+ULoqmCHG1b0LK5WhABiRuYOPv16sfXrUL6E0Fk9IqQiAxTBzWOpkcTQwUMlCLVsgNfHRAE038+Kn8XSt1fjXkR1Ne2c0po4W/kFTW69lFpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SoQnGzbvC7IXy//qY3Etmc+ztTD9ZjxducZ3X6OtCAg=; b=hNUXZrIbieTUVJKplkJ7eIGMd6FDmUtlPkGcd6tQ5Skqh5TLRXB5ri2C1nsmcxQyQr3O7SK8JUhD5i++Eq57FWlHSRu17C2VEtw3uzVenrxrJQ9UbkRlkltGpY7NLkLmynXybnc+sUPBs5wuLAUBaarPt6yUElPN9HTPleCc0AHhqa6Wm1Jp5S60Y/b5XztJfAGrf5QklCeENwKIZG39OIBJf4sL72X5cc63bNmVGoyMfNuhWM+kxRVRJK2JcVf/8Y/wyqEXQpEj16UWIs2IaU67F4VtXEWadvutdzc/XGjeU+puinwSC1Gex6USg8I2HUPYSqHOveMMSV7RuOFYSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SoQnGzbvC7IXy//qY3Etmc+ztTD9ZjxducZ3X6OtCAg=; b=Z8H4ow4GMZloXwn1ykrpTSomkhCnprm8xPFTU7dK3LgvziGoFlUSbYkLkTrNmDnjJIsDFF6NkpI3TU8gVK+KDVqN7sHK2EJ0niFmcFlJ9Bwoy8Mev0oCHQ8lnbO2mf/rOzUd2iol+zkni9WwRu1R089yqS0oF6p9dp2LJNLGqt4= From: Roger Pau Monne To: CC: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 11/11] x86/vpt: introduce a per-vPT lock Date: Wed, 31 Mar 2021 12:33:03 +0200 Message-ID: <20210331103303.79705-12-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210331103303.79705-1-roger.pau@citrix.com> References: <20210331103303.79705-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0077.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::17) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38e6f590-6b03-4422-99d2-08d8f430ded4 X-MS-TrafficTypeDiagnostic: DM4PR03MB5968: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:261; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SHJCVJYXsinhDJK20ruHDKPFq2a/Tfit3eRZDPoiB0xpZUWsLX5ON9RvbIdfybicUnLsDuWg2xSz+T5QxKwxna4eXD1l/FC3TpsUvNPC+o3dmIrMpBNbSSfEVFZOxndV+BVgCgKEtQdKObmRTWaJKyVJIY8TBRX8or+bwTr66YbFhEr/cD1vCGmlzkZGgmanyGGglIgtcqsg/NIEtDNr/BO0P4MWq7G2nslgWyP22bmajqQXhvgCV5+sRMqGMY/HF7+/SibPrY5HtpNNvPLhINblexDeud2dDPWYJfEZrh7K3qfL+jEWDW1R0WUJt7AHjP/MgfU8D5UMlU9K+RYcHXFesj5szUBQVMYhY0HJVGd280JJYwHyQcg8L9UhM6tCVErd/sxKpQCad5k6WF8JGG6/PS/vLDB4tn7gdwy3OdXWJLaaThcY6/gKc4tgvQyMSSMnYO7Fe/vTFm/eO5rronv1HEc2YViREmYAiNCEyCm1gOM64sABNOL1yoGkVnrhAykwUKOPu67M4DnzSS1gcFjob3jnZr0AYC+u7tHUJD4sUMAYfhITt+faNR/A5rfz2Apjd8DZVKpKEkI7nt4t9PDpj/Qn9WJDrwgadBx4ApbPOpX7xGkZHH8SOcbazF6Q14jbeY75VPqKhOxewFGKtA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(366004)(136003)(39860400002)(396003)(26005)(2906002)(6486002)(8676002)(1076003)(36756003)(38100700001)(8936002)(83380400001)(16526019)(86362001)(186003)(6916009)(6496006)(66556008)(66946007)(478600001)(66476007)(5660300002)(316002)(4326008)(2616005)(6666004)(956004)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?GtaSPefGa+b4h9OxJj1+p/7HkWgBF9?= =?utf-8?q?FhyeJWEuwhsdDT+ziLnGkK3dsIlyxzBgXZvYTle2QVWDpjEqORn5zfs7aEI/Qquwh?= =?utf-8?q?h0pE4rRxGbHKqeDI/SxfVPwlbhJNcZ0v8aQBxMm+bq31m1tyiOfRVM7sfimiX81dB?= =?utf-8?q?slDHkAB0HzIDjkZdKXDq9NSWk3R9Fd0pYcyeYHgzb7wOCH7hyPPsHwFwbUv7mGYrY?= =?utf-8?q?LKq8uD0DhIat9hzrK2aR5s+av/V5CQlxjDM7qhbHY/YgER52KqWRsRxeTu9UmCuFk?= =?utf-8?q?osP7joAzfGMCH+IK4Gj2MFxoQvpntU9Ug8ywMs4HDviepH3igDaJp57yesrLbjgPE?= =?utf-8?q?OtuKZ2iLgX5DqI2sSGkcF/UfTNRMGaEdtBuJF35Sl64vqGYoJO7TBED3R2WXBVA+z?= =?utf-8?q?wqjx/liVywsVxeaw1hV4a7v4SFbJoqQaKSTrXb+EsHtKAaa41OXJxy7g1++zm4/Hi?= =?utf-8?q?hTzcHeaq7urtYyfh92snJ+BUwHddYzFPFd47me0W4yj0DX2q6mi1/nINe+FdmYiI9?= =?utf-8?q?k/kYy+kLBzqDssHdPbNmEYXxKbnrSRrDlcARtfTHfukvHIBI6glFc6nny4/4/wBTn?= =?utf-8?q?wjgfpTKBLG5WkHYpWqKluD93JD67GoDyxhi7sU+5eoBMCI4EQHpPUaSX8s5MD2sX4?= =?utf-8?q?xDijlB5zDGhIA+zB9t4QYrTpe+ewJWhmN+rmgzgZ1ri4IDvtLptY1d1sXEc2k2bnO?= =?utf-8?q?3+VeLYKlApBsOJ7y4NIyOsB4jxjcjdRIzh3zRN1o/QgewHh7Z5Q0euv9yXgMCG/kw?= =?utf-8?q?suYsDir9OyaTtbMP6CCVx5XU/FTK1+SLscwAcMEhsOh0n6dRlS6MM02Ngaunn7uZz?= =?utf-8?q?5g4j7VwSxrrrF716w4GWE6TcxGt1wmtBvLI+YCJwTnCNXzwJta4y4tS8xISN/Gpk8?= =?utf-8?q?+zZ1K0yMKl7uwPhLKzIIAHBbpOlD3QdjpfiNxP4Ci3WFNaHvcfK/1t1hUoRu1JQ9W?= =?utf-8?q?jSphcHmWLfARRfYzvDlnxfozw7vUtcXoMzRsmMSnJyBpg43nviCmWagghK+3uLTg2?= =?utf-8?q?Ef8pbYF9v/ar/jZuhJ9Wes7lcZYJ/F3tDfPLRjC1J79heHrwmVVajlr2psn8WW/X/?= =?utf-8?q?GZWLqg5vyqsU68s5/S7CQ4h3p5gnx8rUvnMukw1fhXWAjl62X78eQWPlf8fWcQfKR?= =?utf-8?q?+dzLApSHfucDP2LdaH16EepibmrBNl9oHsNN8Q/Zpsfsi5eybQZiniZse5MJPxZ3n?= =?utf-8?q?ToQvuCLzfqOeJgd4Res5G4dwLMhmuxiJAk4LXQNK80b/sCpWmUJmh9NAtRbdUVI5Q?= =?utf-8?q?MvzHuoMZCLmkcX?= X-MS-Exchange-CrossTenant-Network-Message-Id: 38e6f590-6b03-4422-99d2-08d8f430ded4 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2021 10:36:40.7923 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UzBoUqqnaX7cmcSwvHyMqDesYwrSL0pDPxYDUPnGM9+W02FIX7EwEI8iDYse2fB4RNeVX2AXFpyo028Fh0uI8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5968 X-OriginatorOrg: citrix.com Introduce a per virtual timer lock that replaces the existing per-vCPU and per-domain vPT locks. Since virtual timers are no longer assigned or migrated between vCPUs the locking can be simplified to a in-structure spinlock that protects all the fields. This requires introducing a helper to initialize the spinlock, and that could be used to initialize other virtual timer fields in the future. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v1: - New in his version. --- xen/arch/x86/emul-i8254.c | 1 + xen/arch/x86/hvm/hpet.c | 8 +++++- xen/arch/x86/hvm/hvm.c | 4 --- xen/arch/x86/hvm/rtc.c | 1 + xen/arch/x86/hvm/vlapic.c | 1 + xen/arch/x86/hvm/vpt.c | 48 +++++++++++++++------------------- xen/include/asm-x86/hvm/vcpu.h | 3 --- xen/include/asm-x86/hvm/vpt.h | 9 ++----- 8 files changed, 33 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/emul-i8254.c b/xen/arch/x86/emul-i8254.c index 73be4188ad4..a47138cbab7 100644 --- a/xen/arch/x86/emul-i8254.c +++ b/xen/arch/x86/emul-i8254.c @@ -484,6 +484,7 @@ void pit_init(struct domain *d, unsigned long cpu_khz) { register_portio_handler(d, PIT_BASE, 4, handle_pit_io); register_portio_handler(d, 0x61, 1, handle_speaker_io); + init_periodic_timer(&pit->pt0); } pit_reset(d); diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index ca94e8b4538..20593c3862d 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -739,12 +739,18 @@ static void hpet_set(HPETState *h) void hpet_init(struct domain *d) { + HPETState *h = domain_vhpet(d); + unsigned int i; + if ( !has_vhpet(d) ) return; - hpet_set(domain_vhpet(d)); + hpet_set(h); register_mmio_handler(d, &hpet_mmio_ops); d->arch.hvm.params[HVM_PARAM_HPET_ENABLED] = 1; + + for ( i = 0; i < HPET_TIMER_NUM; i++ ) + init_periodic_timer(&h->pt[i]); } void hpet_deinit(struct domain *d) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 3a72da67ef2..1c014fc26c3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -665,8 +665,6 @@ int hvm_domain_initialise(struct domain *d) /* need link to containing domain */ d->arch.hvm.pl_time->domain = d; - rwlock_init(&d->arch.hvm.pl_time->pt_migrate); - /* Set the default IO Bitmap. */ if ( is_hardware_domain(d) ) { @@ -1556,8 +1554,6 @@ int hvm_vcpu_initialise(struct vcpu *v) hvm_asid_flush_vcpu(v); - spin_lock_init(&v->arch.hvm.tm_lock); - rc = hvm_vcpu_cacheattr_init(v); /* teardown: vcpu_cacheattr_destroy */ if ( rc != 0 ) goto fail1; diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c index 3150f5f1479..2d540b16acd 100644 --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -846,6 +846,7 @@ void rtc_init(struct domain *d) init_timer(&s->update_timer, rtc_update_timer, s, smp_processor_id()); init_timer(&s->update_timer2, rtc_update_timer2, s, smp_processor_id()); init_timer(&s->alarm_timer, rtc_alarm_cb, s, smp_processor_id()); + init_periodic_timer(&s->pt); register_portio_handler(d, RTC_PORT(0), 2, handle_rtc_io); diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 8091b6d8925..688ff85e710 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1651,6 +1651,7 @@ int vlapic_init(struct vcpu *v) return 0; } + init_periodic_timer(&vlapic->pt); vlapic->pt.source = PTSRC_lapic; vlapic->regs_page = alloc_domheap_page(v->domain, MEMF_no_owner); diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c index 84d49c1b25c..9cb0b8a0a82 100644 --- a/xen/arch/x86/hvm/vpt.c +++ b/xen/arch/x86/hvm/vpt.c @@ -126,23 +126,6 @@ static int pt_irq_masked(struct periodic_time *pt) return 1; } -static void pt_lock(struct periodic_time *pt) -{ - /* - * We cannot use pt_vcpu_lock here, because we need to acquire the - * per-domain lock first and then (re-)fetch the value of pt->vcpu, or - * else we might be using a stale value of pt->vcpu. - */ - read_lock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate); - spin_lock(&pt->vcpu->arch.hvm.tm_lock); -} - -static void pt_unlock(struct periodic_time *pt) -{ - spin_unlock(&pt->vcpu->arch.hvm.tm_lock); - read_unlock(&pt->vcpu->domain->arch.hvm.pl_time->pt_migrate); -} - static void pt_process_missed_ticks(struct periodic_time *pt) { s_time_t missed_ticks, now = NOW(); @@ -213,7 +196,7 @@ static void pt_timer_fn(void *data) void *cb_priv; unsigned int irq; - pt_lock(pt); + spin_lock(&pt->lock); v = pt->vcpu; irq = pt->irq; @@ -228,7 +211,7 @@ static void pt_timer_fn(void *data) cb_priv = pt->priv; } - pt_unlock(pt); + spin_unlock(&pt->lock); if ( cb ) cb(v, cb_priv); @@ -245,7 +228,7 @@ static void eoi_callback(unsigned int unused, void *data) time_cb *cb = NULL; void *cb_priv; - pt_lock(pt); + spin_lock(&pt->lock); pt_irq_fired(pt->vcpu, pt); if ( pt->pending_intr_nr && inject_interrupt(pt) ) @@ -256,7 +239,7 @@ static void eoi_callback(unsigned int unused, void *data) v = pt->vcpu; } - pt_unlock(pt); + spin_unlock(&pt->lock); if ( cb ) cb(v, cb_priv); @@ -312,6 +295,11 @@ static bool inject_interrupt(struct periodic_time *pt) return true; } +void init_periodic_timer(struct periodic_time *pt) +{ + spin_lock_init(&pt->lock); +} + void create_periodic_time( struct vcpu *v, struct periodic_time *pt, uint64_t delta, uint64_t period, uint8_t irq, time_cb *cb, void *data, bool level) @@ -328,7 +316,7 @@ void create_periodic_time( destroy_periodic_time(pt); - write_lock(&v->domain->arch.hvm.pl_time->pt_migrate); + spin_lock(&pt->lock); pt->pending_intr_nr = 0; @@ -391,18 +379,21 @@ void create_periodic_time( init_timer(&pt->timer, pt_timer_fn, pt, v->processor); set_timer(&pt->timer, pt->scheduled); - write_unlock(&v->domain->arch.hvm.pl_time->pt_migrate); + spin_unlock(&pt->lock); } void destroy_periodic_time(struct periodic_time *pt) { unsigned int gsi; + spin_lock(&pt->lock); /* Was this structure previously initialised by create_periodic_time()? */ if ( pt->vcpu == NULL ) + { + spin_unlock(&pt->lock); return; + } - pt_lock(pt); pt->pending_intr_nr = 0; gsi = pt->irq; @@ -415,7 +406,7 @@ void destroy_periodic_time(struct periodic_time *pt) hvm_gsi_unregister_callback(pt->vcpu->domain, gsi, &pt->eoi_cb); break; } - pt_unlock(pt); + spin_unlock(&pt->lock); /* * pt_timer_fn() can run until this kill_timer() returns. We must do this @@ -430,10 +421,13 @@ static void pt_resume(struct periodic_time *pt) time_cb *cb = NULL; void *cb_priv; + spin_lock(&pt->lock); if ( pt->vcpu == NULL ) + { + spin_unlock(&pt->lock); return; + } - pt_lock(pt); if ( pt->pending_intr_nr && inject_interrupt(pt) ) { pt->pending_intr_nr--; @@ -441,7 +435,7 @@ static void pt_resume(struct periodic_time *pt) cb_priv = pt->priv; v = pt->vcpu; } - pt_unlock(pt); + spin_unlock(&pt->lock); if ( cb ) cb(v, cb_priv); diff --git a/xen/include/asm-x86/hvm/vcpu.h b/xen/include/asm-x86/hvm/vcpu.h index 9a756964fb0..fe3d0e10426 100644 --- a/xen/include/asm-x86/hvm/vcpu.h +++ b/xen/include/asm-x86/hvm/vcpu.h @@ -148,9 +148,6 @@ struct hvm_vcpu { s64 cache_tsc_offset; u64 guest_time; - /* Lock for virtual platform timers. */ - spinlock_t tm_lock; - bool flag_dr_dirty; bool debug_state_latch; bool single_step; diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h index af04efa5e01..5628cff8f7a 100644 --- a/xen/include/asm-x86/hvm/vpt.h +++ b/xen/include/asm-x86/hvm/vpt.h @@ -48,6 +48,7 @@ struct periodic_time { time_cb *cb; void *priv; /* point back to platform time source */ struct hvm_gsi_eoi_callback eoi_cb; /* EOI callback registration data */ + spinlock_t lock; }; @@ -126,13 +127,6 @@ struct pl_time { /* platform time */ struct RTCState vrtc; struct HPETState vhpet; struct PMTState vpmt; - /* - * rwlock to prevent periodic_time vCPU migration. Take the lock in read - * mode in order to prevent the vcpu field of periodic_time from changing. - * Lock must be taken in write mode when changes to the vcpu field are - * performed, as it allows exclusive access to all the timers of a domain. - */ - rwlock_t pt_migrate; /* guest_time = Xen sys time + stime_offset */ int64_t stime_offset; /* Ensures monotonicity in appropriate timer modes. */ @@ -167,6 +161,7 @@ void create_periodic_time( struct vcpu *v, struct periodic_time *pt, uint64_t delta, uint64_t period, uint8_t irq, time_cb *cb, void *data, bool level); void destroy_periodic_time(struct periodic_time *pt); +void init_periodic_timer(struct periodic_time *pt); int pv_pit_handler(int port, int data, int write); void pit_reset(struct domain *d);