From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D5E7C433EF for ; Thu, 30 Sep 2021 13:22:19 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id EF17E61278 for ; Thu, 30 Sep 2021 13:22:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EF17E61278 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 671CA4B0DF; Thu, 30 Sep 2021 09:22:18 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gC2ydJVwu33K; Thu, 30 Sep 2021 09:22:16 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 815D54B0CC; Thu, 30 Sep 2021 09:22:16 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7F67B4B0C0 for ; Thu, 30 Sep 2021 09:22:15 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DzA43qi053tD for ; Thu, 30 Sep 2021 09:22:11 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C692049DE3 for ; Thu, 30 Sep 2021 09:22:11 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633008131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6ckZ1pppA29wAm+9rfiJ1n/Mo/PrqlcBv4nOphRPsTU=; b=bgoUezSBdcbSFe8dYmIp32yOXQf+Np7LDWovTfzFQU0JjDDqNvDaYT8cGhtWwClCIPKaVC LJYjznrBXdfZ000QEQzcKWpaTAp+E0YcXvluR4dRteAiwthjEan2wEyOyR+FMJ3VjLTICj 5hIih4E1JDgvw1q2Ma46o+WCz4bPuWc= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-BTX9GaDFNg2oG4hndA7dyQ-1; Thu, 30 Sep 2021 09:22:08 -0400 X-MC-Unique: BTX9GaDFNg2oG4hndA7dyQ-1 Received: by mail-qk1-f199.google.com with SMTP id t2-20020a05620a450200b0045e34e4f9c7so13265400qkp.18 for ; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6ckZ1pppA29wAm+9rfiJ1n/Mo/PrqlcBv4nOphRPsTU=; b=elmrpyOKL65wkgOqG3SOyvBK/BJ6a0UUwXabJcJKinX2xTSUc6z5OSrFuwt3u6CQjc 4oKlA+7pqMkVAwKpJXONlXFdTcJI1A5UQjed+SF8kQHXrItuCn13ulPaIbNZRuVjpV91 AU0w7bDn7EbP8hFws4j1Y4BXWxpsM20OSLCV37NrXIv4FeKGzhd6FoaL0nJq5dkXm3rr INXXa/yS7NdMwWGguLN5MuEqjCEW5A5khqdzsWdI8z9kK0x0LxZzVckqahqgD5j2mRm8 vVdHL/X3DU8gMh1MWqco04JUkZZ0A1/E5HM30+AxFOQe5sKet8cMu1haB3BDAZRyYdf9 JZUQ== X-Gm-Message-State: AOAM530DeE8or1fixwPo1wVm+Q8yuVuj3UmQE0+cI45tw+acDiPW4uUT QGylf0T2Ix6Xfqb/j3gtIguBgSfZ5l3hBGy+pb9lHkJ4VZzgrhahlJkAMFPLdbVygl5NUasJoUQ ArXkKoPggc2Ye49qWjoq2ycmc X-Received: by 2002:a37:d82:: with SMTP id 124mr4751622qkn.299.1633008128508; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygLLhtXJjxjuaO0dACez2L3lInr7k748BHulrSq78dll6LEjGrJO1fGfBl8yf2p3YtMw287A== X-Received: by 2002:a37:d82:: with SMTP id 124mr4751602qkn.299.1633008128329; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) Received: from gator (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id h4sm1586843qtb.67.2021.09.30.06.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:22:07 -0700 (PDT) Date: Thu, 30 Sep 2021 15:22:04 +0200 From: Andrew Jones To: Alexandru Elisei Subject: Re: [PATCH 1/2] KVM: arm64: Return early from read_id_reg() if register is RAZ Message-ID: <20210930132204.m7l4tdzzenllnr6h@gator> References: <20210927124911.191729-1-alexandru.elisei@arm.com> <20210927124911.191729-2-alexandru.elisei@arm.com> MIME-Version: 1.0 In-Reply-To: <20210927124911.191729-2-alexandru.elisei@arm.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: maz@kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Mon, Sep 27, 2021 at 01:49:10PM +0100, Alexandru Elisei wrote: > If read_id_reg() is called for an ID register which is Read-As-Zero > (RAZ), it initializes the return value to zero, then goes through a list > of registers which require special handling. > > By not returning as soon as it tests if the register is RAZ, it creates > the opportunity for bugs, if a patch changes a register to RAZ (like has > happened with PMSWINC_EL0 in commit 11663111cd49), but doesn't remove the > special handling from read_id_reg(); or if a register is RAZ in certain > situations, and readable in others. > > Return early as to make it impossible for a RAZ register to be anything > other than zero. > > Signed-off-by: Alexandru Elisei > --- > arch/arm64/kvm/sys_regs.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 1d46e185f31e..4adda8bf3168 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1064,7 +1064,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, > struct sys_reg_desc const *r, bool raz) > { > u32 id = reg_to_encoding(r); > - u64 val = raz ? 0 : read_sanitised_ftr_reg(id); > + u64 val; > + > + if (raz) > + return 0; > + > + val = read_sanitised_ftr_reg(id); > > switch (id) { > case SYS_ID_AA64PFR0_EL1: > -- > 2.33.0 > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm > Reviewed-by: Andrew Jones _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBC71C433FE for ; Thu, 30 Sep 2021 13:29:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 B9ECA61528 for ; Thu, 30 Sep 2021 13:29:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B9ECA61528 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Voz2wqu6r1GQZ3ElNUJBl5SuYHYYy4HpDOp4UdXiTkE=; b=QfkeQNWNc8W5zu SMgcKoazqtA6E2Wst9NIbY45crVbaoQJOzAGstkrwq/8QidT6xSxZUDFmu+gxSxTinNJyKZ6uHx+1 f8G9gJhVgNCYEM1zDs0jGT1IHXjbHCNp4l5PggVEvhhRmbAdqoU+tDc9/5Ryj9haiLfxdQXdOwpef dmxZU0wtXRsOHYf/ubBN6CcfoXEatJ9HSX6CLvZsSHN/5yqFQ3beJnsnLp5G3hu1WiYlZrtoD0BiX e9v9uwYoSaRUv502abk+VctG6zK9ETpx6WD+//Pev5UydApeJu/oXMBnLTmRp6G9eWW9xgRiDv2Eo t9gpxdp1oBEFxyNJ1HjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVw3q-00ESMa-6C; Thu, 30 Sep 2021 13:25:18 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVw0w-00ERDo-QY for linux-arm-kernel@lists.infradead.org; Thu, 30 Sep 2021 13:22:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633008135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6ckZ1pppA29wAm+9rfiJ1n/Mo/PrqlcBv4nOphRPsTU=; b=ZGXJGWRv+AnWwcTS1bwRE6JqFJFwaCLEJP1HNFUAp3K+tGXfAeGa1sIQLqTEqF9eQIuiPH bylSZDlTXUTm6e7owjIVPAb67R6YskDoXHQ/7t5eRmCflwKKdcdMXnRrttjLaitrO7c0j/ iEZ3z/4O0Xb8jGYWZcIdNfQbYyEu3Lg= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-OJvWtoatPgy8qDMPyvwOvQ-1; Thu, 30 Sep 2021 09:22:09 -0400 X-MC-Unique: OJvWtoatPgy8qDMPyvwOvQ-1 Received: by mail-qk1-f197.google.com with SMTP id j6-20020a05620a288600b0045e5d85ca17so13213151qkp.16 for ; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6ckZ1pppA29wAm+9rfiJ1n/Mo/PrqlcBv4nOphRPsTU=; b=kZ4+gmKfOIk4pN7xrRbeP/GlkREWx4uNwqi7F6ssZR7jx7ifDy/UWpnI4U4I5j7wnS HM3dNRWezpQrdPJeXBEtieVLPFCcpC7eBT5FoPyRilYyjurkghc6DfQTvLS2AJs3Xspt rHg6WjAP183sruJxAtJmV51L1oVyWYUV1vbaZMEik7pAToEu6iR1KpBpenK0ZsLzHevF mZeLbhTfLvjpBeo7+qNvA+dPv+U0J3Zwk7S4V2dB/mXs4wqxl5/2c3vpIlHIuxY3dSwJ IMncz7VaFPPTbnCYoSjNaXgmsNOzomdYZLOxtbcI3xwJImMEtbTOcvPOjyCL2PwDtfLK /8JA== X-Gm-Message-State: AOAM532glAbKzBpC7QsffWohbcyOld9EsDKTTQ6HG4fg5pJGEt50xMBp 97wXZsOS4CZsMhp6wrScDu4Rxi8QHW1KOR0caeVJTnLsib1Zb5kKkeHilUSoayjFsyPF/wbUsfS 20T+HOLOhWEIsTtXFUo0xgGl5phZxp6aH2AU= X-Received: by 2002:a37:d82:: with SMTP id 124mr4751621qkn.299.1633008128507; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygLLhtXJjxjuaO0dACez2L3lInr7k748BHulrSq78dll6LEjGrJO1fGfBl8yf2p3YtMw287A== X-Received: by 2002:a37:d82:: with SMTP id 124mr4751602qkn.299.1633008128329; Thu, 30 Sep 2021 06:22:08 -0700 (PDT) Received: from gator (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id h4sm1586843qtb.67.2021.09.30.06.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:22:07 -0700 (PDT) Date: Thu, 30 Sep 2021 15:22:04 +0200 From: Andrew Jones To: Alexandru Elisei Cc: maz@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH 1/2] KVM: arm64: Return early from read_id_reg() if register is RAZ Message-ID: <20210930132204.m7l4tdzzenllnr6h@gator> References: <20210927124911.191729-1-alexandru.elisei@arm.com> <20210927124911.191729-2-alexandru.elisei@arm.com> MIME-Version: 1.0 In-Reply-To: <20210927124911.191729-2-alexandru.elisei@arm.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=drjones@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210930_062218_994361_E76485FF X-CRM114-Status: GOOD ( 25.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Sep 27, 2021 at 01:49:10PM +0100, Alexandru Elisei wrote: > If read_id_reg() is called for an ID register which is Read-As-Zero > (RAZ), it initializes the return value to zero, then goes through a list > of registers which require special handling. > > By not returning as soon as it tests if the register is RAZ, it creates > the opportunity for bugs, if a patch changes a register to RAZ (like has > happened with PMSWINC_EL0 in commit 11663111cd49), but doesn't remove the > special handling from read_id_reg(); or if a register is RAZ in certain > situations, and readable in others. > > Return early as to make it impossible for a RAZ register to be anything > other than zero. > > Signed-off-by: Alexandru Elisei > --- > arch/arm64/kvm/sys_regs.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 1d46e185f31e..4adda8bf3168 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1064,7 +1064,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, > struct sys_reg_desc const *r, bool raz) > { > u32 id = reg_to_encoding(r); > - u64 val = raz ? 0 : read_sanitised_ftr_reg(id); > + u64 val; > + > + if (raz) > + return 0; > + > + val = read_sanitised_ftr_reg(id); > > switch (id) { > case SYS_ID_AA64PFR0_EL1: > -- > 2.33.0 > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm > Reviewed-by: Andrew Jones _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel