From patchwork Thu Sep 26 18:37:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174514 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438550ill; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwjHFVY9iC0hDL5hgz15GRSX74fjYEHxCw0z8iOZzN8kN9aXNimzWPtt4K2hV4JhoiVXL2 X-Received: by 2002:a92:af15:: with SMTP id n21mr15226ili.224.1569523196270; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523196; cv=none; d=google.com; s=arc-20160816; b=kVNw+suYZ8ycHVysFmKJpWqkrPeqm9pqw/tvPXRRIZW7GsdlaLU9rW9lntvGe6/QW1 ukyxwnfzNsjPD6mGPC5n9EsRs5PwJlZNwr6jlTwJ+aUt7BCfqiuwrxFhgzKq+jn80RVj HLc8Yl5q8bYkONAed53/q9cmtflygpvPimE/Jd7jsRYUiQLXjKGJzPzNvlotGtU3ne0K DsmZ+KXuq7/ZvA3EaH3TM+yjSwDVnjP3iVgjV8z1PbJwXJaJJVuWDk8rqAeTzDFBoEBk Mt8whSPkxXE/bF6HXs6AI8YWfdQy05ShgRo2g4aDu+0cF2Qtlwb3hAdR3Z7O1Gf0yUw4 segQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=BdskQHunxWm6sUNJmdg7n48ru+EAdQwUMzylK7eqyAQ=; b=NGuDBWFnHyYnyy0v6resN613mqZ/eDrf/nyJAdezZuoi31N2qqJRoF4BeTBR+nt/XP O6Si+RP+jTb5ALxKQ+ZqBX3G87aLQvUMAyuIAKLHf+7wJ/pqmMGVixSrB3TUEdym3UZX /APlPLfa5ulsRZk8eTzkLDLm9A56uMFhPLCED10Ln/s68tv0IYxBIUblXYKdZEpRwRbO uS0lKIvEMoT2k9qgnAuZ9QFumr1CAOjGwDSWl2qF+1bLoEqs4joQQosiiJi0aTHbHBrn fBpLhikj/ocECGnwQS+ALtQgcB/9o4HINpUYyN4wt8hYeoundCDBBAoCWKP4pTz4Z1qz LCAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a1si184918ilp.82.2019.09.26.11.39.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYeg-0002O6-6E; Thu, 26 Sep 2019 18:38:18 +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.89) (envelope-from ) id 1iDYee-0002Ns-7s for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:16 +0000 X-Inumbo-ID: cca6d78e-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id cca6d78e-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:14 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4FB631570; Thu, 26 Sep 2019 11:38:14 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 834B93F67D; Thu, 26 Sep 2019 11:38:13 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:37:59 +0100 Message-Id: <20190926183808.11630-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 01/10] xen/arm64: entry: Introduce a macro to generate guest vector and use it X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Most of the guest vectors are using the same pattern. This makes fairly tedious to alter the pattern and risk introducing mistakes when updating each path. A new macro is introduced to generate the guest vectors and now use it in the one that use the open-code version. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Reviewed-by: Stefano Stabellini --- xen/arch/arm/arm64/entry.S | 84 ++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 2d9a2713a1..8665d2844a 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -157,6 +157,30 @@ .endm + /* + * Generate a guest vector. + * + * iflags: Correspond to the list of interrupts to unmask + * save_x0_x1: See the description on top of the macro 'entry' + */ + .macro guest_vector compat, iflags, trap, save_x0_x1=1 + entry hyp=0, compat=\compat, save_x0_x1=\save_x0_x1 + /* + * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT + * is not set. If a vSError took place, the initial exception will be + * skipped. Exit ASAP + */ + ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", + "nop; nop", + SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) + msr daifclr, \iflags + mov x0, sp + bl do_trap_\trap +1: + exit hyp=0, compat=\compat + .endm + + /* * Bad Abort numbers *----------------- @@ -290,36 +314,10 @@ guest_sync_slowpath: * x0/x1 may have been scratch by the fast path above, so avoid * to save them. */ - entry hyp=0, compat=0, save_x0_x1=0 - /* - * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT - * is not set. If a vSError took place, the initial exception will be - * skipped. Exit ASAP - */ - ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", - "nop; nop", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) - msr daifclr, #6 - mov x0, sp - bl do_trap_guest_sync -1: - exit hyp=0, compat=0 + guest_vector compat=0, iflags=6, trap=guest_sync, save_x0_x1=0 guest_irq: - entry hyp=0, compat=0 - /* - * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT - * is not set. If a vSError took place, the initial exception will be - * skipped. Exit ASAP - */ - ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", - "nop; nop", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) - msr daifclr, #4 - mov x0, sp - bl do_trap_irq -1: - exit hyp=0, compat=0 + guest_vector compat=0, iflags=4, trap=irq guest_fiq_invalid: entry hyp=0, compat=0 @@ -333,36 +331,10 @@ guest_error: exit hyp=0, compat=0 guest_sync_compat: - entry hyp=0, compat=1 - /* - * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT - * is not set. If a vSError took place, the initial exception will be - * skipped. Exit ASAP - */ - ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", - "nop; nop", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) - msr daifclr, #6 - mov x0, sp - bl do_trap_guest_sync -1: - exit hyp=0, compat=1 + guest_vector compat=1, iflags=6, trap=guest_sync guest_irq_compat: - entry hyp=0, compat=1 - /* - * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT - * is not set. If a vSError took place, the initial exception will be - * skipped. Exit ASAP - */ - ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", - "nop; nop", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) - msr daifclr, #4 - mov x0, sp - bl do_trap_irq -1: - exit hyp=0, compat=1 + guest_vector compat=1, iflags=4, trap=irq guest_fiq_invalid_compat: entry hyp=0, compat=1 From patchwork Thu Sep 26 18:38:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174506 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438511ill; Thu, 26 Sep 2019 11:39:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzajZow1ePK1Z1ZcFby0sfB7rkiE3f2aUSdfFwLkNTCpaZ68TYZogDJX9xq549mONRibSZ X-Received: by 2002:a5d:8851:: with SMTP id t17mr4669285ios.250.1569523195303; Thu, 26 Sep 2019 11:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523195; cv=none; d=google.com; s=arc-20160816; b=MoamT5QktyDvhB7FkunaiRxTmJp2v2tBKrMNyXuCWQyl72y2pSdctBx85reIJ7Ih9Z 4hZSE3ltP+/L8fg/wUAGlLazOXabcaJW+zpuBW+BIZcRrV/TQsEZuFb48Hq11xL4t/d+ pUAjI9cjL3fZxqoh9gKWWgfFY7tu2cm0MNeqN44baS/yf6444QUz0C0Fvrbrl8xn05+d Ot2Zi68w7+60IRcApviKg7nqQeRcOsuwMmeLH1Ch+GAPj7SLR6LZ0A/EtoOcyF6cD3lh FvZ9bl4wai5/CTWW4gX/DLenuYdg37V3+urZFsAyaLfuMoEYxEmnjk6h278cszPG9sO4 Uvrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=12Gpp2LuYCSKfYI8cf4cC7TmJMqRitLQTVo4r62EI8Q=; b=xMvNHieXQjimmvfT5NoXNwMLkrSSN+l2PaLPPo+wtgr9/0n1JTNW9S08iNTJbVEzQc nFrN4cwZ7kc8X67a/Lu4m25phlTNFHJwvtfGSEtglh+YDlcY35qQlJWgfJ3B8mCJoypx nFjUEzuKmYIYkPU/AYl5M82Hg9G2jROUFgyIy0bcWYX9W0mr8smdf7z+yDMugnc6MXGe 2CwDmkusFQKiXRzwDN87iMkO9vbf6jV7nvs2zvwTkB3Ytk4cCzffCdiO8Q5NcrMXJgRt EBm4lX/oBmJVl7nJ/pgwMvhEHPcxikj1BiTWzrh2yu3f13VSFH7Xe9kOw7nlPw42pLGV kPWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n6si149440ile.150.2019.09.26.11.39.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYek-0002OS-Gz; Thu, 26 Sep 2019 18:38:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYei-0002OC-Qo for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:20 +0000 X-Inumbo-ID: cd4a7fb0-e08c-11e9-97fb-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id cd4a7fb0-e08c-11e9-97fb-bc764e2007e4; Thu, 26 Sep 2019 18:38:15 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 50DD81596; Thu, 26 Sep 2019 11:38:15 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8487C3F67D; Thu, 26 Sep 2019 11:38:14 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:00 +0100 Message-Id: <20190926183808.11630-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 02/10] xen/arm64: head: Check if an SError is pending when receiving a vSError X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, when we receive an SError exception from the guest, we don't check if there are any other pending. For hardening the code, we should ensure any pending SError are accounted to the guest before executing any code with SError unmasked. The recently introduced macro 'guest_vector' could used to generate the two vectors and therefore take advantage of any change required in the future. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Reviewed-by: Stefano Stabellini --- xen/arch/arm/arm64/entry.S | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 8665d2844a..40d9f3ec8c 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -324,11 +324,7 @@ guest_fiq_invalid: invalid BAD_FIQ guest_error: - entry hyp=0, compat=0 - msr daifclr, #6 - mov x0, sp - bl do_trap_guest_serror - exit hyp=0, compat=0 + guest_vector compat=0, iflags=6, trap=guest_serror guest_sync_compat: guest_vector compat=1, iflags=6, trap=guest_sync @@ -341,11 +337,7 @@ guest_fiq_invalid_compat: invalid BAD_FIQ guest_error_compat: - entry hyp=0, compat=1 - msr daifclr, #6 - mov x0, sp - bl do_trap_guest_serror - exit hyp=0, compat=1 + guest_vector compat=1, iflags=6, trap=guest_serror ENTRY(return_to_new_vcpu32) exit hyp=0, compat=1 From patchwork Thu Sep 26 18:38:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174515 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438572ill; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPmCjLD7dANFJ89nzMY+/hJnrYdWcTjWG7YI2YLYu2coMOcSKeJmT2Z8fqEW+gPYyEbEqw X-Received: by 2002:a6b:c9d7:: with SMTP id z206mr4557981iof.172.1569523197415; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523197; cv=none; d=google.com; s=arc-20160816; b=xGWiXYZRlru5/rmOvItxgIac5/rKCu6FxJf5wWtqsG8ExOsxUXpsT1zxcgpZqth/4A IvTQgwcqLwX5wkV6DtNwo9rmZGQ/Ob/i903R3RiN1E94LqNJz+AZ+OiqSDinJlU4+jXN 3XWQ1ysSQy+6SBbiu+vF/Cpe9bQ3UrUtcQ/ArR7BsZ3sjb07z//vWEzLgxnoj89/EWAL bqSH0FU6ejBhIMrjdRq+8uPOl9I3oELWoY4jMECsfL6A5YZCtguuIyEqe2G6lBGLpDUD 46AgFeAXh4fQtX8pR95vkrAfOuc/UgCKyR6vbRACnVF4Hlw6P4VWYmgBOzkmYLgFixHi pylg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=YqB0DLp3rncukWuHk8c1p8Aly8k8iATEA01FgEGsPPY=; b=phm+vD1Jrn9K3SKW3IcN0d3EMJyS0UPeJ7iMXEzLPuZhlyCkOvY20lXyc3LeiQQ3iR 597JZPaYlTuHnA4Fqz8UXt4qR+uvHOah/jEdhA4KuIyPIHDhlMFHfGXi1fUkr4zogBbF k0LQfhICh0mW5U/iE4u6PSUTE+eK8xldHobl6ihcn8EhVT6/TYr5UFajky8NVaOpbZ9C 3+K58C0ku+DOMQ4QXXsiGf1OxgCfQBX3gea3rt8mUl7uBCvh56vuhtWi5ijeqD2je5KU ++yfyo92A9mVQWbeGsL55bELvGDNlv+pkHKyJ2Kvf/7p+sWEHEouXjzcRWrQ//z7IPcp PsHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 77si198559ilv.72.2019.09.26.11.39.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYek-0002Ob-Qo; Thu, 26 Sep 2019 18:38:22 +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.89) (envelope-from ) id 1iDYej-0002OH-4C for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:21 +0000 X-Inumbo-ID: cddbbc6e-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id cddbbc6e-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:16 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 521AA142F; Thu, 26 Sep 2019 11:38:16 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 85B833F67D; Thu, 26 Sep 2019 11:38:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:01 +0100 Message-Id: <20190926183808.11630-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 03/10] xen/arm: traps: Rework entry/exit from the guest path X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, enter_hypervisor_head() and leave_hypervisor_tail() are used to deal with actions to be done before/after any guest request is handled. While they are meant to work in pair, the former is called for most of the traps, including traps from the same exception level (i.e. hypervisor) whilst the latter will only be called when returning to the guest. As pointed out, the enter_hypervisor_head() is not called from all the traps, so this makes potentially difficult to extend it for the dealing with same exception level. Furthermore, some assembly only path will require to call enter_hypervisor_tail(). So the function is now directly call by assembly in for guest vector only. This means that the check whether we are called in a guest trap can now be removed. Take the opportunity to rename enter_hypervisor_tail() and leave_hypervisor_tail() to something more meaningful and document them. This should help everyone to understand the purpose of the two functions. Signed-off-by: Julien Grall --- I haven't done the 32-bits part yet. I wanted to gather feedback before looking in details how to integrate that with Arm32. --- xen/arch/arm/arm64/entry.S | 4 ++- xen/arch/arm/traps.c | 71 ++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 40d9f3ec8c..9eafae516b 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -147,7 +147,7 @@ .if \hyp == 0 /* Guest mode */ - bl leave_hypervisor_tail /* Disables interrupts on return */ + bl leave_hypervisor_to_guest /* Disables interrupts on return */ exit_guest \compat @@ -175,6 +175,8 @@ SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) msr daifclr, \iflags mov x0, sp + bl enter_hypervisor_from_guest + mov x0, sp bl do_trap_\trap 1: exit hyp=0, compat=\compat diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index a3b961bd06..20ba34ec91 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2006,47 +2006,46 @@ static inline bool needs_ssbd_flip(struct vcpu *v) cpu_require_ssbd_mitigation(); } -static void enter_hypervisor_head(struct cpu_user_regs *regs) +/* + * Actions that needs to be done after exiting the guest and before any + * request from it is handled. + */ +void enter_hypervisor_from_guest(struct cpu_user_regs *regs) { - if ( guest_mode(regs) ) - { - struct vcpu *v = current; + struct vcpu *v = current; - /* If the guest has disabled the workaround, bring it back on. */ - if ( needs_ssbd_flip(v) ) - arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL); + /* If the guest has disabled the workaround, bring it back on. */ + if ( needs_ssbd_flip(v) ) + arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL); - /* - * If we pended a virtual abort, preserve it until it gets cleared. - * See ARM ARM DDI 0487A.j D1.14.3 (Virtual Interrupts) for details, - * but the crucial bit is "On taking a vSError interrupt, HCR_EL2.VSE - * (alias of HCR.VA) is cleared to 0." - */ - if ( v->arch.hcr_el2 & HCR_VA ) - v->arch.hcr_el2 = READ_SYSREG(HCR_EL2); + /* + * If we pended a virtual abort, preserve it until it gets cleared. + * See ARM ARM DDI 0487A.j D1.14.3 (Virtual Interrupts) for details, + * but the crucial bit is "On taking a vSError interrupt, HCR_EL2.VSE + * (alias of HCR.VA) is cleared to 0." + */ + if ( v->arch.hcr_el2 & HCR_VA ) + v->arch.hcr_el2 = READ_SYSREG(HCR_EL2); #ifdef CONFIG_NEW_VGIC - /* - * We need to update the state of our emulated devices using level - * triggered interrupts before syncing back the VGIC state. - * - * TODO: Investigate whether this is necessary to do on every - * trap and how it can be optimised. - */ - vtimer_update_irqs(v); - vcpu_update_evtchn_irq(v); + /* + * We need to update the state of our emulated devices using level + * triggered interrupts before syncing back the VGIC state. + * + * TODO: Investigate whether this is necessary to do on every + * trap and how it can be optimised. + */ + vtimer_update_irqs(v); + vcpu_update_evtchn_irq(v); #endif - vgic_sync_from_lrs(v); - } + vgic_sync_from_lrs(v); } void do_trap_guest_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr }; - enter_hypervisor_head(regs); - switch ( hsr.ec ) { case HSR_EC_WFI_WFE: @@ -2180,8 +2179,6 @@ void do_trap_hyp_sync(struct cpu_user_regs *regs) { const union hsr hsr = { .bits = regs->hsr }; - enter_hypervisor_head(regs); - switch ( hsr.ec ) { #ifdef CONFIG_ARM_64 @@ -2218,27 +2215,21 @@ void do_trap_hyp_sync(struct cpu_user_regs *regs) void do_trap_hyp_serror(struct cpu_user_regs *regs) { - enter_hypervisor_head(regs); - __do_trap_serror(regs, VABORT_GEN_BY_GUEST(regs)); } void do_trap_guest_serror(struct cpu_user_regs *regs) { - enter_hypervisor_head(regs); - __do_trap_serror(regs, true); } void do_trap_irq(struct cpu_user_regs *regs) { - enter_hypervisor_head(regs); gic_interrupt(regs, 0); } void do_trap_fiq(struct cpu_user_regs *regs) { - enter_hypervisor_head(regs); gic_interrupt(regs, 1); } @@ -2281,7 +2272,13 @@ static void check_for_vcpu_work(void) local_irq_disable(); } -void leave_hypervisor_tail(void) +/* + * Actions that needs to be done before entering the guest. This is the + * last thing executed before the guest context is fully restored. + * + * The function will return with interrupts disabled. + */ +void leave_hypervisor_to_guest(void) { local_irq_disable(); From patchwork Thu Sep 26 18:38:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174516 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438574ill; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLfQc2B7RiLnJY6Rjn/gb65AD9Qmo3FWiXFCyrWN1L8KkaznylYsR3xRaFHh1O9kfDG0cQ X-Received: by 2002:a6b:4407:: with SMTP id r7mr4620482ioa.85.1569523197522; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523197; cv=none; d=google.com; s=arc-20160816; b=SadSp6qDuVWI8kU+HKUG9XHtcx+WSo2NAWDgtCm8UNr9KuVhGnsvbhrVQ1HMekbglu yv86VXXrq/kDsM4LjNL51Tif3Ot/YDHweuFLLscxhe6+mSOm7Yd9+p3mwifg/SIf/FPR f9t9YvbGmpLrNgThBSjw49IowTZvP/sl4NrbvhsgPvDWhkYb2w34pvldQx2ZTR0gRQ6G r9sm9B0z67aKjxlymGjzgQHSCZ+r1gb4nPeI88WL7ZIvJZ2rtFY6/ijdXCH0OdGkxttC L3SdD9tj6XUgnFLLyATMxwRCl/SUIZsThuquMeZ7f5UVY8ixkeSW6WPRulHy1u3AAW7C QchQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=gf+eBqwuHqYTi+BPzbtgFxCKh5BgA23cWNMUDc5gaYU=; b=i0C2/yIw9kRKxrRqWFcFdKkjOAKWJ/PYHOSCjex0FQ7Vez6/qAIP6f6uTZsA01gjq5 LFemv8xxxEbtoU3nBj0bLn6oBQbH4dbBoqwTLtWSjFpsQ9lQZ4Hsmrm/hX/wtdpBiBrd 2fOmVJfQDtMlaEVvqqaKhDbCBbIk5VKnkonGHr9sjHeJkwFWtPkxxi2cNt7rFiy9dC40 1UKAimsW9UUw8SiH/WREsjQNAHljh/KzCcbSwpCRPJFXxxPmkx67O4thfMd4+GBsybYZ r6y6lZ2SlgfqzaEuitciZq0+4ZJLSS8plDkUMEFPa7MpyjOmjynpNhyBocq5j45O3Li1 vHuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p21si4012759jah.4.2019.09.26.11.39.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYep-0002PQ-4r; Thu, 26 Sep 2019 18:38:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYen-0002PG-QK for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:25 +0000 X-Inumbo-ID: ce82bf0a-e08c-11e9-97fb-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id ce82bf0a-e08c-11e9-97fb-bc764e2007e4; Thu, 26 Sep 2019 18:38:17 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E9AB15A2; Thu, 26 Sep 2019 11:38:17 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8727F3F67D; Thu, 26 Sep 2019 11:38:16 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:02 +0100 Message-Id: <20190926183808.11630-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 04/10] xen/arm: Ensure the SSBD workaround is re-enabled right after exiting a guest X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrii Anisov , Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, SSBD workaround is re-enabled for Xen after interrupts are unmasked. This means we may end up to execute some part of the hypervisor if an interrupt is received before the workaround is re-enabled. As the rest of enter_hypervisor_from_guest() does not require to have interrupts masked, the function is now split in two parts: 1) enter_hypervisor_from_guest_noirq() called with interrupts masked. 2) enter_hypervisor_from_guest() called with interrupts unmasked. Note that while enter_hypervisor_from_guest_noirq() does not use the on-stack context registers, it is still passed as parameter to match the rest of the C functions called from the entry path. Fixes: a7898e4c59 ("xen/arm: Add ARCH_WORKAROUND_2 support for guests") Reported-by: Andrii Anisov Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk --- Note the Arm32 code has not been changed yet. I am also open on turn both enter_hypervisor_from_guest_noirq() and enter_hypervisor_from() to functions not taking any parameters. --- xen/arch/arm/arm64/entry.S | 2 ++ xen/arch/arm/traps.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 9eafae516b..458d12f188 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -173,6 +173,8 @@ ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", "nop; nop", SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) + mov x0, sp + bl enter_hypervisor_from_guest_noirq msr daifclr, \iflags mov x0, sp bl enter_hypervisor_from_guest diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 20ba34ec91..5848dd8399 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2007,16 +2007,26 @@ static inline bool needs_ssbd_flip(struct vcpu *v) } /* - * Actions that needs to be done after exiting the guest and before any - * request from it is handled. + * Actions that needs to be done after exiting the guest and before the + * interrupts are unmasked. */ -void enter_hypervisor_from_guest(struct cpu_user_regs *regs) +void enter_hypervisor_from_guest_noirq(struct cpu_user_regs *regs) { struct vcpu *v = current; /* If the guest has disabled the workaround, bring it back on. */ if ( needs_ssbd_flip(v) ) arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2_FID, 1, NULL); +} + +/* + * Actions that needs to be done after exiting the guest and before any + * request from it is handled. Depending on the exception trap, this may + * be called with interrupts unmasked. + */ +void enter_hypervisor_from_guest(struct cpu_user_regs *regs) +{ + struct vcpu *v = current; /* * If we pended a virtual abort, preserve it until it gets cleared. From patchwork Thu Sep 26 18:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174513 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438551ill; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpGbUO5hKu9vjMdpWG/w7kiHv5sdUZBNn646wqNDd5yFt1vg5qdIzgr8PzdC7yu8UGvyfA X-Received: by 2002:a6b:8d06:: with SMTP id p6mr4392642iod.219.1569523196618; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523196; cv=none; d=google.com; s=arc-20160816; b=pKpaLmAivUOWyYIR3In+v8sSPnBMV1raLR1B9YJQ69CaQ2LjI82Cbnf8xZ97xxBgYh ITPf+YPtMHF+E54Z6L85KSjkiwsSeTb3L5qOExm36vU7XjOdNREPd7zG0OM+gcYb9gOy k6f0xRqjIRU9wmG1SngxmzgmQQhuSGvqtHgtDZCZtTFmp8mAwKf7jCtgvwAS7RL5fDkb LQfwBMXaW9uhHFW0bn4Psp4HI9ekDjim6N2lv8LVj9OQpLLUIuihC269trYFN3ML/WZa 8P0j7BLJu4Hc7GlOP+yxL3+8warqREdJo1hr8LGXlkVNENKXrvVXbpMhQ5zxOLgGxGUS DuWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=pb6ppKmzDdc45ve1UlSMO6QmUZRgbMTrJlrL++C+nSw=; b=B5hogp/F+W+Q4qkIeZkBTwN0N+hcl97Wk3I369ZrEJYX5wh1RHtrVni9n5NN20N7Sm GFc67b11HyXfeWBG7qinFmbTjh9D3wfpCDn5J8/wZz7d2FrrkC23x9JDsVAjfqn2Seog lpXAZDIiUk2h2nsz5J4oP7T6G42YKuhr06FwfUCGAdcPMjmY+53579zxa6lfnSoGAAs0 HVeuc91wcxjZpEtwujfT8ZvKoJR2627AtYF0pQ995aWlAQfQpkFxNuvnKWmuCOEcOmlM oyBdEYKX2XOLyx4eYX8CShcVQcW4TJosZzPHiySQHDZ0/7Oew/qdpwbo1URu5GK+L/zI ZmSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id w29si175494ilk.119.2019.09.26.11.39.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYet-0002Sr-W4; Thu, 26 Sep 2019 18:38:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYes-0002Rw-QZ for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:30 +0000 X-Inumbo-ID: cf323ec6-e08c-11e9-97fb-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id cf323ec6-e08c-11e9-97fb-bc764e2007e4; Thu, 26 Sep 2019 18:38:18 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 705BA1596; Thu, 26 Sep 2019 11:38:18 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A36583F67D; Thu, 26 Sep 2019 11:38:17 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:03 +0100 Message-Id: <20190926183808.11630-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 05/10] xen/arm: alternative: Remove unused parameter for alternative_if_not_cap X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The macro alternative_if_not_cap is taking two parameters. The second parameter is never used and it is hard to see how this can be used correctly as it is only protecting the alternative section magic. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Acked-by: Stefano Stabellini --- xen/include/asm-arm/alternative.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xen/include/asm-arm/alternative.h b/xen/include/asm-arm/alternative.h index dedb6dd001..2830a6da2d 100644 --- a/xen/include/asm-arm/alternative.h +++ b/xen/include/asm-arm/alternative.h @@ -116,13 +116,11 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en * The code that follows this macro will be assembled and linked as * normal. There are no restrictions on this code. */ -.macro alternative_if_not cap, enable = 1 - .if \enable +.macro alternative_if_not cap .pushsection .altinstructions, "a" altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f .popsection 661: - .endif .endm /* From patchwork Thu Sep 26 18:38:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174510 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438531ill; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSKzxbbXX6tGeCAUrU23csZlBV7vvFyGbllHXywzjP5wz5g0M3MopjyR6RJ7JKXzbdf++d X-Received: by 2002:a92:1756:: with SMTP id u83mr6818ill.264.1569523196011; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523196; cv=none; d=google.com; s=arc-20160816; b=MH2p2jESZRS2KEUgx1tyECvPBQkMZo6Ox8YiN/2H9Twm7YwUnEg4WXD5DpnIiY3NeW cAwlz8H3V5Hj6vknRsBGOCIUVpMZ5SwaAxkOWf6HpuTw+fj5THKWxH88edWikZItZg5+ H9tLAHzgIKJWbNpsjMlbLB0PUrtS68BEJFtMC7QoY8TjBGfiGyRLZF5disoDOl8MneCK COJX+FS5eiZoRiY4h+3dwopMhPkZcht+a3vkefqc9lqHD2Iu5sXNeUqyxHO5IS/oJGdE tlJQhGr31Xy3txH3ymQd/fZcugX+boIlcl0Rlv0BKMS05QyzKZtLJ3aG5mli0fDn0GSc HneQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=+A6ioyAOmjeTa+KXW3MQv0dW/wNEUp2hOCZGYYTNeL0=; b=jp1MewfiG+XNNZrKC16Gb8u7vCZO2RiKg5P2oSEaruaam+y9StH9hB/353bLP6pFkS aWW5sNn3ga9+FA98Ciatpdkj/srBePPlc5scmCdK5uPba3Vv9t9k7pmTwowdStweE83a 5Ec3d6I1H4h8Hw8GcM5w7xE2qJdRtksjKXP5MfhqD/c96bLvvXwtanhIogAZHaaBiYv2 Bg9gVM2DAThmxyJbD6QZ1ykuyxMP5CmiickGZGijELVnkIazxQhpbpHx6DQELTxmSrAK ow46onIavJ9Ahx4dI4weP/W7XO5AbdX046xAx+xww1gHVfQ0v2OJHyZSLgtWErvHEn3r QFAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n18si3849063ion.158.2019.09.26.11.39.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYep-0002Pe-Lf; Thu, 26 Sep 2019 18:38:27 +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.89) (envelope-from ) id 1iDYeo-0002PL-49 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:26 +0000 X-Inumbo-ID: cfdb28f6-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id cfdb28f6-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:19 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A81F815AB; Thu, 26 Sep 2019 11:38:19 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A5A503F67D; Thu, 26 Sep 2019 11:38:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:04 +0100 Message-Id: <20190926183808.11630-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 06/10] xen/arm: Move ARCH_PATCH_INSN_SIZE out of the header livepatch.h X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Konrad Rzeszutek Wilk , andrii.anisov@gmail.com, Ross Lagerwall , Julien Grall , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, ARCH_PATCH_INSN_SIZE is defined in the header livepatch.h. However, this is also used in the alternative code. Rather than including livepatch.h just for using the define, move it in the header insn.h which seems more suitable. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Reviewed-by: Ross Lagerwall Acked-by: Stefano Stabellini --- xen/arch/arm/alternative.c | 2 -- xen/include/asm-arm/insn.h | 3 +++ xen/include/asm-arm/livepatch.h | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 52ed7edf69..237c4e5642 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -30,8 +30,6 @@ #include #include #include -/* XXX: Move ARCH_PATCH_INSN_SIZE out of livepatch.h */ -#include #include /* Override macros from asm/page.h to make them work with mfn_t */ diff --git a/xen/include/asm-arm/insn.h b/xen/include/asm-arm/insn.h index 3489179826..19277212e1 100644 --- a/xen/include/asm-arm/insn.h +++ b/xen/include/asm-arm/insn.h @@ -11,6 +11,9 @@ # error "unknown ARM variant" #endif +/* On ARM32,64 instructions are always 4 bytes long. */ +#define ARCH_PATCH_INSN_SIZE 4 + #endif /* !__ARCH_ARM_INSN */ /* * Local variables: diff --git a/xen/include/asm-arm/livepatch.h b/xen/include/asm-arm/livepatch.h index 6bca79deb9..026af5e7dc 100644 --- a/xen/include/asm-arm/livepatch.h +++ b/xen/include/asm-arm/livepatch.h @@ -7,9 +7,7 @@ #define __XEN_ARM_LIVEPATCH_H__ #include /* For SZ_* macros. */ - -/* On ARM32,64 instructions are always 4 bytes long. */ -#define ARCH_PATCH_INSN_SIZE 4 +#include /* * The va of the hypervisor .text region. We need this as the From patchwork Thu Sep 26 18:38:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174511 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438541ill; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqYhW+0X/Q6L4ow7xCQqB8I4ZS8sjrVsZqsF4mw6LfyeB8MsqjDCzeydH8X0NJdELQadlg X-Received: by 2002:a92:a1d6:: with SMTP id b83mr40159ill.76.1569523196209; Thu, 26 Sep 2019 11:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523196; cv=none; d=google.com; s=arc-20160816; b=lbsIuDK6X4zazekZ+oUsyQPhbGJ2Me35XVeQu5AqyzdHOH94myzLueGAcxnXQc64YM MR+WqjpXpn3p51WpGBITF0QYdMvt7ERc5UZqS/XGVJ+7DgnLjf1bSVSmmO98kCotvM+O rlfAipCLbwShz3OdlxM1XPiE7nYKJ65jaOd/r4h5AvT8W8Zw1xilUGIJX4HDRixjraXi hNgNFGF1J/edS+m2sAbfoTw2Af671Fep7T157FRdP9/jFy5/M8NYiZCQF1C5DDPd+/f3 paDl40P9PSQZZkt//V7R58dSQX45vv7VbcpWWetqi2jk8R+J0m39Xmk2eqCGpZ0/xTQP Avsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=+WNix94WXENy11ScBvtZFxBuZanH1pejqmx0BuMpOHg=; b=U2HoK7/24+mGUQEda9xGLt84z4IrXdCKyWdIWvW2JQpkmW5nI9Ce/TU+jqlS/SPb6k fDdE6qNTP8jRoicnlnUzQlTA+a1GRDKH83P4mJQw96VNdVqyME4OQyJIi5m/SwVmJyET l4jkYjSQOWe8VWkftbfh7dWoN+FyTSZYQjmqPgEKBhc4HGJZxMPmmQb0fnet1KW50536 O2eOnknA4A/B8vGBMSe0adGZk2fQ3uhCb4oxDIcSaHgDm8HpH5xkxyz4DmE2uhe7jDYf A+Y0QXx7g8GWXOMtoD90SejuPEVgotAuh+sd+hfaB5IIbYl0K++CrAfxKyGO5HDZ41nv 6jLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id z13si193429iln.102.2019.09.26.11.39.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYeu-0002TI-C9; Thu, 26 Sep 2019 18:38: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.89) (envelope-from ) id 1iDYet-0002SL-4A for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:31 +0000 X-Inumbo-ID: d0838a78-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id d0838a78-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:21 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A932A142F; Thu, 26 Sep 2019 11:38:20 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DCD553F67D; Thu, 26 Sep 2019 11:38:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:05 +0100 Message-Id: <20190926183808.11630-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 07/10] xen/arm: Allow insn.h to be called from assembly X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A follow-up patch will require to include insn.h from assembly code. So wee need to protect any C-specific definition to avoid compilation error when used in assembly code. Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk --- xen/include/asm-arm/insn.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/include/asm-arm/insn.h b/xen/include/asm-arm/insn.h index 19277212e1..00391f83f9 100644 --- a/xen/include/asm-arm/insn.h +++ b/xen/include/asm-arm/insn.h @@ -1,8 +1,14 @@ #ifndef __ARCH_ARM_INSN #define __ARCH_ARM_INSN +#ifndef __ASSEMBLY__ + #include +/* + * At the moment, arch-specific headers contain only definition for C + * code. + */ #if defined(CONFIG_ARM_64) # include #elif defined(CONFIG_ARM_32) @@ -11,6 +17,8 @@ # error "unknown ARM variant" #endif +#endif /* __ASSEMBLY__ */ + /* On ARM32,64 instructions are always 4 bytes long. */ #define ARCH_PATCH_INSN_SIZE 4 From patchwork Thu Sep 26 18:38:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174508 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438567ill; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvNISm19HdnYMhioOgLlxqcvzRR2AbGexpi5GUa8hRgGxSczAP/gbgeo8Y34I6ldfeTJDe X-Received: by 2002:a92:8fcf:: with SMTP id r76mr38496ilk.82.1569523197235; Thu, 26 Sep 2019 11:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523197; cv=none; d=google.com; s=arc-20160816; b=0TOfWEjqZxNpf2AZy2ZxnmX01RX325r6iTldATCPCOUecvrxTqoxy/kQoBnu6YZgVc CYZX3BnpC6ZBinSrOmggk/161KA0a6qIG2eQFgVyy1IOf+Zg2aIx0FD/ZOZKouNX/py/ plHXRaiUeOaxVrqolYuNeBRRJHM+KhjD4RFk4JBatX/RCM9F525Dgvpxc8KULm+Ru9Ii 51KDVX4kErQbX78aHIHWkr0eEMuMXhAiM8E0qCbi+/oeWpPvT994Dw+OJSSpZkegN2zz uh9pIPh1UkxI2LYpcY9PxZT9PN1kfonENVfkKww/b/TOKWnWhOhyredZ8IVUOhrLoQP8 T/ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=peISiiDsVz2y1o66WMSnPzdzcKgF6IQKKa+47rDKy3w=; b=oisBDxFJXuQq+Mo8bM97wgHUw8jecjaDqUGEUwX6nt73A654zFb7OXdPbfgCwDaqxb ZjXUkGv9C0nReGw6vi2IZquQ1boYh4nMXIgVwRPdocuPpdigKPN3ttFu1ygQ7jZN+bBT 5XX8FAWXppTNoNmVGIYc72phJaL2+B6JQawlVpNndvwU27lgGNtCK0sdbsXfHSog7WCk 93p91I0i7+eW/VkIhb0cFkv2bMKnUhUFZEb0XY7QOeMBeoOisdT6dE7brG/DxG7BygSj HDoFya/WKHVQfttGvxo+ZjfVajdBn1uz3QU8lGaGAkZAsoTDt6DiNI6hEHlwQvvOR9m6 b0IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id f72si160603ild.149.2019.09.26.11.39.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYf0-0002XA-3S; Thu, 26 Sep 2019 18:38:38 +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.89) (envelope-from ) id 1iDYey-0002Vc-4Q for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:36 +0000 X-Inumbo-ID: d140d3da-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id d140d3da-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:22 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E260A1570; Thu, 26 Sep 2019 11:38:21 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE5EE3F67D; Thu, 26 Sep 2019 11:38:20 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:06 +0100 Message-Id: <20190926183808.11630-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 08/10] xen/arm: alternative: add auto-nop infrastructure X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Stefano Stabellini , Will Deacon , andrii.anisov@gmail.com, Julien Grall , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Mark Rutland In some cases, one side of an alternative sequence is simply a number of NOPs used to balance the other side. Keeping track of this manually is tedious, and the presence of large chains of NOPs makes the code more painful to read than necessary. To ameliorate matters, this patch adds a new alternative_else_nop_endif, which automatically balances an alternative sequence with a trivial NOP sled. In many cases, we would like a NOP-sled in the default case, and instructions patched in in the presence of a feature. To enable the NOPs to be generated automatically for this case, this patch also adds a new alternative_if, and updates alternative_else and alternative_endif to work with either alternative_if or alternative_endif. The alternative infrastructure was originally ported from Linux. So this is pretty much a straight backport from commit 792d47379f4d "arm64: alternative: add auto-nop infrastructure". The only difference is the nops macro added as not yet existing in Xen. Signed-off-by: Mark Rutland [will: use new nops macro to generate nop sequences] Signed-off-by: Will Deacon [julien: Add nops and port to Xen] Signed-off-by: Julien Grall Reviewed-by: Volodymyr Babchuk Acked-by: Stefano Stabellini --- xen/include/asm-arm/alternative.h | 70 +++++++++++++++++++++++++++++---------- xen/include/asm-arm/macros.h | 7 ++++ 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/xen/include/asm-arm/alternative.h b/xen/include/asm-arm/alternative.h index 2830a6da2d..e8271ac04e 100644 --- a/xen/include/asm-arm/alternative.h +++ b/xen/include/asm-arm/alternative.h @@ -2,6 +2,7 @@ #define __ASM_ALTERNATIVE_H #include +#include #define ARM_CB_PATCH ARM_NCAPS @@ -111,34 +112,55 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .endm /* - * Begin an alternative code sequence. + * Alternative sequences + * + * The code for the case where the capability is not present will be + * assembled and linked as normal. There are no restrictions on this + * code. + * + * The code for the case where the capability is present will be + * assembled into a special section to be used for dynamic patching. + * Code for that case must: + * + * 1. Be exactly the same length (in bytes) as the default code + * sequence. * - * The code that follows this macro will be assembled and linked as - * normal. There are no restrictions on this code. + * 2. Not contain a branch target that is used outside of the + * alternative sequence it is defined in (branches into an + * alternative sequence are not fixed up). + */ + +/* + * Begin an alternative code sequence. */ .macro alternative_if_not cap + .set .Lasm_alt_mode, 0 .pushsection .altinstructions, "a" altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f .popsection 661: .endm +.macro alternative_if cap + .set .Lasm_alt_mode, 1 + .pushsection .altinstructions, "a" + altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f + .popsection + .pushsection .altinstr_replacement, "ax" + .align 2 /* So GAS knows label 661 is suitably aligned */ +661: +.endm + /* - * Provide the alternative code sequence. - * - * The code that follows this macro is assembled into a special - * section to be used for dynamic patching. Code that follows this - * macro must: - * - * 1. Be exactly the same length (in bytes) as the default code - * sequence. - * - * 2. Not contain a branch target that is used outside of the - * alternative sequence it is defined in (branches into an - * alternative sequence are not fixed up). + * Provide the other half of the alternative code sequence. */ .macro alternative_else -662: .pushsection .altinstr_replacement, "ax" +662: + .if .Lasm_alt_mode==0 + .pushsection .altinstr_replacement, "ax" + .else + .popsection + .endif 663: .endm @@ -154,12 +176,26 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en * Complete an alternative code sequence. */ .macro alternative_endif -664: .popsection +664: + .if .Lasm_alt_mode==0 + .popsection + .endif .org . - (664b-663b) + (662b-661b) .org . - (662b-661b) + (664b-663b) .endm /* + * Provides a trivial alternative or default sequence consisting solely + * of NOPs. The number of NOPs is chosen automatically to match the + * previous case. + */ +.macro alternative_else_nop_endif +alternative_else + nops (662b-661b) / ARCH_PATCH_INSN_SIZE +alternative_endif +.endm + +/* * Callback-based alternative epilogue */ .macro alternative_cb_end diff --git a/xen/include/asm-arm/macros.h b/xen/include/asm-arm/macros.h index 1d4bb41d15..91ea3505e4 100644 --- a/xen/include/asm-arm/macros.h +++ b/xen/include/asm-arm/macros.h @@ -13,4 +13,11 @@ # error "unknown ARM variant" #endif + /* NOP sequence */ + .macro nops, num + .rept \num + nop + .endr + .endm + #endif /* __ASM_ARM_MACROS_H */ From patchwork Thu Sep 26 18:38:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174512 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438630ill; Thu, 26 Sep 2019 11:40:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxtrnMmEqOBUkQVgOC/Y7ZPpwAppYx23ML81s9yq82e0BDKTaWzLwybxtwjvkCv181+Dl7L X-Received: by 2002:a5e:d502:: with SMTP id e2mr4588080iom.279.1569523200663; Thu, 26 Sep 2019 11:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523200; cv=none; d=google.com; s=arc-20160816; b=f7c3fOUZVPM7S57Hv7PQJFB4cqXUHCX+CSTT4Yn05+IB6fM62y/cowaVy3V1lgO+xf H49+SEhtpjG2afZW5hqOHlZO54SbA69rLi0h7fVWLZsiZgr+I4S0UfZqFLo4i/qxympD X+tpoNast+BXY6SKiVxjqJ0lv2YfIse6d7duJiZhyQOodTu3k4B2qSMDYO8+M8ZeuMJ6 MKD1YoW5CianwaXVa4GopsHVurLKbBMyGv2nfiqBS9ZMC60auDQ4JPV7WcC218mxCCqp IEttVPNTvFAABwkhRk7ImxpF0Nr4g/fx8EhbxRTuCrXzaTZT2AGqnoncuSDeXP6F0e2g 34CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=32L0Z8wYIbL4i89i5/ng56acnJMijNFsQitRLGljrQY=; b=IYWSykXiafCBa7xYkSp8xnE9Iz/VK2LZ07UWBZMp/SMj22AVmSBeTCIaA5mBmT/ifO S+gJU6xkWxhFgUhlL9LVnLblKQ8DnD3xZDvEEOIkI0gUX6AIvk8NncjBJtxfPi27Dto3 QSLHKByf2SiD34xbeiqBowOLrypN4IEXEtw0jBtKTNcHhOAqgnWAuQ2JCUs0lMOYbAU7 HFfefSH/VTTVf/2BWgRULUwYH63ermbPoAfjO5Pv8mZHBNfX6aqe9xm54IcllpgfJvdQ 7M9EkxF1aIG5XoMsomlH4h3a9vdjrsKIbER4bCXydcNWN7fS9JhPPIRxxXGwxEN9pQe2 1ptg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id z22si184512ilf.71.2019.09.26.11.40.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:40:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYf3-0002aO-Fx; Thu, 26 Sep 2019 18:38:41 +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.89) (envelope-from ) id 1iDYf3-0002a0-4n for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:41 +0000 X-Inumbo-ID: d1bc3ba6-e08c-11e9-965e-12813bfff9fa Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id d1bc3ba6-e08c-11e9-965e-12813bfff9fa; Thu, 26 Sep 2019 18:38:23 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E3DF5142F; Thu, 26 Sep 2019 11:38:22 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 232163F67D; Thu, 26 Sep 2019 11:38:22 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:07 +0100 Message-Id: <20190926183808.11630-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 09/10] xen/arm: asm: Replace use of ALTERNATIVE with alternative_if X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Using alternative_if makes the code a bit more streamlined. Take the opportunity to use the new auto-nop infrastructure to avoid counting the number of nop in the else part for arch/arm/arm64/entry.S Signed-off-by: Julien Grall Reviewed-By: Volodymyr Babchuk Reviewed-by: Volodymyr Babchuk --- This is pretty much a matter of taste, but at least for arm64 this allows us to use the auto-nop infrastructure. So the arm32 is more to keep inline with arm64. --- xen/arch/arm/arm32/entry.S | 9 ++++++--- xen/arch/arm/arm64/entry.S | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/arm32/entry.S b/xen/arch/arm/arm32/entry.S index 0b4cd19abd..1428cd3583 100644 --- a/xen/arch/arm/arm32/entry.S +++ b/xen/arch/arm/arm32/entry.S @@ -65,9 +65,12 @@ save_guest_regs: * If the SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT has been set in the cpu * feature, the checking of pending SErrors will be skipped. */ - ALTERNATIVE("nop", - "b skip_check", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) + alternative_if SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT + nop + alternative_else + b skip_check + alternative_endif + /* * Start to check pending virtual abort in the gap of Guest -> HYP * world switch. diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 458d12f188..91cf6ee6f4 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -170,9 +170,11 @@ * is not set. If a vSError took place, the initial exception will be * skipped. Exit ASAP */ - ALTERNATIVE("bl check_pending_vserror; cbnz x0, 1f", - "nop; nop", - SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT) + alternative_if SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT + bl check_pending_vserror + cbnz x0, 1f + alternative_else_nop_endif + mov x0, sp bl enter_hypervisor_from_guest_noirq msr daifclr, \iflags From patchwork Thu Sep 26 18:38:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 174509 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2438608ill; Thu, 26 Sep 2019 11:39:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyo4/Ky3IQ8nwTAgNO5N/lco6sZ1NunV/txnlOP9Hi3YnK1WSVog4hpjiw3pIg1oLpAPPyH X-Received: by 2002:a92:1ddd:: with SMTP id g90mr4165597ile.235.1569523199119; Thu, 26 Sep 2019 11:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569523199; cv=none; d=google.com; s=arc-20160816; b=FlrhwUX3rsmKkXKm50pRe2MAnfcQIXWmdtYaxXMvGKu/eBoeSo9dNrcILKkxtEtpNa TwQqjYgxS7RVeMkGZP5PHcrPwT2sRzN38MZiUtXCGdVPC1xCnYLkjsdHkRRNp2K4zonz rJj6NdIv3TCOPZm/+mXJm9qQzBliYXAG7yY6gu2OYN8FfgnPdFsUhXdOh4vnFabNXUrc /yfIt+zUW+9Nl7QWtfgTCk3qnUldRNwhQqjZwfl9y999AqkYvSO2ftNtfOdpdcvJmIYm Rjk0BLdDJsjWG5Yf79y32NRWrEWyWbWMDn1MxY9tMKK4nMWRSKPngqDW1pYSszeHGHSw zEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=3jI7bDrhfgIXnb+tp9qRcjmlC5K4DHknW47hlKOjGgM=; b=ZdN7lW9v9Xf4tGpK3xHucOyotMGd+dBzI82k++bxxWDTNbXdlWNWVAeW0FiiBvjUxh UAXe4tgNmzZams5lEuxKVTQ40mb/4Fc3/3DRgfc36wnhuPevoXGTCpEYbckEz0WNXCy4 m25WmJZ828ep19SRJv9WiAlZzJWkl7AQZDI5s2WlHyale552jyGNuTnNfanTxgwQRERX R1pgj97nCgzK7rE94qh0cN5RRnDlFEjceK07omCpaYQ+fqX41G9drL9VbQlTxvgXW6R0 5UZoAoLmDp7cp0NdkvSYZsQqiWhKj9LiEsNSQRXm56jn27A/8HJ33/ILXrjwCbb8/2Q2 FaXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id r62si193634ill.74.2019.09.26.11.39.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Sep 2019 11:39:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYey-0002WA-OA; Thu, 26 Sep 2019 18:38:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDYex-0002VO-R0 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 18:38:35 +0000 X-Inumbo-ID: d2557d98-e08c-11e9-b588-bc764e2007e4 Received: from foss.arm.com (unknown [217.140.110.172]) by localhost (Halon) with ESMTP id d2557d98-e08c-11e9-b588-bc764e2007e4; Thu, 26 Sep 2019 18:38:24 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E54BF1596; Thu, 26 Sep 2019 11:38:23 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2499B3F67D; Thu, 26 Sep 2019 11:38:23 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 19:38:08 +0100 Message-Id: <20190926183808.11630-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190926183808.11630-1-julien.grall@arm.com> References: <20190926183808.11630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH RFC for-4.13 10/10] xen/arm64: entry: Ensure the guest state is synced when receiving a vSError X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , Stefano Stabellini , Volodymyr Babchuk , andrii.anisov@gmail.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, when a SError is received while checking for a pending one, we will skip the handling the initial exception. This includes call to exit_from_guest{, _noirq} that is used to synchronize part of the guest state with the internal representation. However, we still call leave_hypervisor_tail() which is used for preempting the guest and synchronizing back part of the guest state. exit_from_guest{, _noirq} works in pair with leave_hypervisor_tail(), so skipping if former may result to a loss of some part of guest state. An example is the new vGIC which will save the state of the LRS on exit from the guest and rewrite all of them on entry to the guest. For now, calling leave_hypervisor_tail() is not necessary when injecting a vSError to the guest. But as the path is spread accross multiple file, it is hard to enforce that for the future (someone we may want to crash the domain). Therefore it is best to call exit_from_guest{, _noirq} in the vSError path as well. Note that the return value of check_pending_vserror is now set in x19 instead of x0. This is because we want to keep the value across call to C-function and x0, unlike x19, will not be saved by the callee. Signed-off-by: Julien Grall --- I am not aware of any issues other than with the new vGIC. But I haven't looked hard enough so I think it would be worth to try to fix it for Xen 4.13. --- xen/arch/arm/arm64/entry.S | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S index 91cf6ee6f4..f5350247e1 100644 --- a/xen/arch/arm/arm64/entry.S +++ b/xen/arch/arm/arm64/entry.S @@ -168,11 +168,13 @@ /* * The vSError will be checked while SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT * is not set. If a vSError took place, the initial exception will be - * skipped. Exit ASAP + * skipped. + * + * However, we still need to call exit_from_guest{,_noirq} as the + * return path to the guest may rely on state saved by them. */ alternative_if SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT bl check_pending_vserror - cbnz x0, 1f alternative_else_nop_endif mov x0, sp @@ -180,6 +182,11 @@ msr daifclr, \iflags mov x0, sp bl enter_hypervisor_from_guest + + alternative_if SKIP_SYNCHRONIZE_SERROR_ENTRY_EXIT + cbnz x19, 1f + alternative_else_nop_endif + mov x0, sp bl do_trap_\trap 1: @@ -383,9 +390,9 @@ return_from_trap: /* * This function is used to check pending virtual SError in the gap of * EL1 -> EL2 world switch. - * The x0 register will be used to indicate the results of detection. - * x0 -- Non-zero indicates a pending virtual SError took place. - * x0 -- Zero indicates no pending virtual SError took place. + * The register x19 will be used to indicate the results of detection. + * x19 -- Non-zero indicates a pending virtual SError took place. + * x19 -- Zero indicates no pending virtual SError took place. */ check_pending_vserror: /* @@ -432,9 +439,9 @@ abort_guest_exit_end: /* * Not equal, the pending SError exception took place, set - * x0 to non-zero. + * x19 to non-zero. */ - cset x0, ne + cset x19, ne ret