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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C2B13C25B4E for ; Sun, 22 Jan 2023 17:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xl11xyEUHxCRUbS+tc9L4wGhixWjcuvHGYkpYmt80d4=; b=19R/9quj9wfX3h RjO5ODpol953IHiBkcUhx6nxWcaGGjCuQ5H5BAk+/RBR8Rsx7Oz+2iEZ45Blrk1FyxADeegBjJH0T NLsf2z1mg+51aS6O4qFZkvomm33tyz3F24tRKAmekrrBvB9cFHt2XhCiET19mnrCodstlvQqDkExC EN1jVQOt8vdqsEoh7ZW+AmEth6ks4dS6Hnh1Ky4sgJBLiL0ar5q2+yj7GqmGfGeFtelVS7BkgJDhK VpFUopN/5c2HWS1+CxyTR0foeTilqE4TaA8VC6Dwv7MwT/rBzm0m/JP7T39MJnc3AzGW2ORT6+8RB OcjHrbkLslAAoQKuB2Kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJeGy-00FbOH-PN; Sun, 22 Jan 2023 17:36:52 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJeGt-00FbNY-F0 for linux-arm-kernel@lists.infradead.org; Sun, 22 Jan 2023 17:36:51 +0000 Received: by mail-pl1-x62e.google.com with SMTP id z13so9393749plg.6 for ; Sun, 22 Jan 2023 09:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=L1k4meEZKAf66tXkdJ6J+WHVPbucWvBqpX+pVJTA9ys=; b=NwV1e5R86M8bWtBaV9Vpay6r6PfoafmwPNhyWdCu7Hu167lD7SHHy4jE4UAQww1HrJ AU9gXKGJCAc/mKWOWkxz4bO1TgXiJsa+J+3omqVKZ6xu2O04HKb5KDOVFlIN6XUTmF8M DeA+sSjnH97ke06KhesBtPVgt5+65aoWg8yB60uHPzmsXkjOdaJbBhTvoHNWp9YQbM/6 tkznctEKHX6c1VXCmvWgnL31Yneg53whju87EmQ1C8iGH78hQkSj7r12uvhfZ3t4/dN5 9iDJYiST+NwMCgcuOh2yajkhWZ/74RISH1rvbj79G3rw8jxhuR6WaWMxftD9QkogzKDv GlKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L1k4meEZKAf66tXkdJ6J+WHVPbucWvBqpX+pVJTA9ys=; b=2ZLBMUdISEueFDCFTUqLLgGM6lWz9lilzrczDvWMkTfCpEsuCgs1IYxMeR76g/fqcD pNxilpTn4yz/f50uYrnG6tb7fhoBNizXNWHE7uXKfhL7GAc8Gp4GF/b4FtFoqGb08QBR LMWg15CdxSXqMge4eYPT2jrDY4XUXDJo4OP5WUo0ejwpnyFldyT28vy+AnIh1U5S4xGG RCXuqoSXy9X9JOxEN5Y1tOgV1GnVr3M7yjl4CUTpS6oU8fMnrCxOBd0rHr0u9n86LNsj nxvs6+MGp+n5CNXxzDKmeWh/P3KeWi7kLKHu0zPId2mWH1ktMdv+/BZtCACwiISOhfhr PByg== X-Gm-Message-State: AFqh2kqlFe/Mt38d8ge30Ie/YSlWPV0JGO1yIoEvTSgoUqWduYCH4WH/ VL3CrHRuCg62gLb5GF0jMfM= X-Google-Smtp-Source: AMrXdXsYR9jO+MVSpwBqH1qbiNlY6WO5wHP4lSotgKN8fOpSdehAs7Zn12h8/hDF614Pfk1RDz4mew== X-Received: by 2002:a17:902:c3cd:b0:193:3154:5c86 with SMTP id j13-20020a170902c3cd00b0019331545c86mr24991131plj.21.1674409005506; Sun, 22 Jan 2023 09:36:45 -0800 (PST) Received: from ?IPV6:2400:4050:a840:1e00:4457:c267:5e09:481b? ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id cp19-20020a170902e79300b00177efb56475sm6787098plb.85.2023.01.22.09.36.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Jan 2023 09:36:44 -0800 (PST) Message-ID: <0ac18497-8392-8ea3-05ee-7f2377a4374c@gmail.com> Date: Mon, 23 Jan 2023 02:36:39 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v7 7/7] KVM: arm64: Normalize cache configuration Content-Language: en-US To: Oliver Upton , Marc Zyngier Cc: Akihiko Odaki , Mark Brown , linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mathieu Poirier , Suzuki K Poulose , Alexandru Elisei , James Morse , Will Deacon , Catalin Marinas , asahi@lists.linux.dev, Alyssa Rosenzweig , Sven Peter , Hector Martin References: <20230112023852.42012-1-akihiko.odaki@daynix.com> <20230112023852.42012-8-akihiko.odaki@daynix.com> <86k01gm6ys.wl-maz@kernel.org> From: Akihiko Odaki In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230122_093647_573566_628D2881 X-CRM114-Status: GOOD ( 25.34 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023/01/22 3:15, Oliver Upton wrote: > Hey Marc, > > On Sat, Jan 21, 2023 at 12:02:03PM +0000, Marc Zyngier wrote: >> On Thu, 19 Jan 2023 19:46:16 +0000, Oliver Upton wrote: >>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >>> index 459e6d358dab..b6228f7d1d8d 100644 >>> --- a/arch/arm64/kvm/sys_regs.c >>> +++ b/arch/arm64/kvm/sys_regs.c >>> @@ -148,17 +148,19 @@ static u32 get_ccsidr(struct kvm_vcpu *vcpu, u32 csselr) >>> >>> static int set_ccsidr(struct kvm_vcpu *vcpu, u32 csselr, u32 val) >>> { >>> - u8 line_size = FIELD_GET(CCSIDR_EL1_LineSize, val); >>> + u8 line_size = SYS_FIELD_GET(CCSIDR_EL1, LineSize, val); >>> + u32 cur = get_ccsidr(vcpu, csselr); >>> + u8 min_line_size = SYS_FIELD_GET(CCSIDR_EL1, LineSize, cur); >>> u32 *ccsidr = vcpu->arch.ccsidr; >>> u32 i; >>> >>> - if ((val & CCSIDR_EL1_RES0) || line_size < get_min_cache_line_size(csselr)) >>> + if (cur == val) >>> + return 0; >>> + >>> + if ((val & CCSIDR_EL1_RES0) || line_size < min_line_size) >>> return -EINVAL; >> >> This doesn't look right. You're comparing the value userspace is >> trying to set for a given level with the value that is already set for >> that level, and forbid the cache line size to be smaller. It works if >> no value has been set yet (you fallback to something derived from >> CTR_EL0), but this fails if userspace does multiple writes. > > Good catch, I tried to skip over the unit/field conversions by doing this > but it has the consequence of not working as expected for multiple writes. > >> The original check is against CTR_EL0, which makes absolute sense >> because we want to check across the whole hierarchy. It is just that >> the original code has two bugs: >> >> - It fails to convert the CCSIDR_EL1.LineSize value to a number of >> words (the missing +4). Admire how the architecture is actively >> designed to be hostile to SW by providing two different formats for >> the cache line size, none of which is in... bytes. >> >> - It passes the full CSSELR value to get_min_cache_line_size(), while >> this function wants a bool... Yes, there are times where you'd want >> a stronger type system (did anyone say Rust? ;-) > > Hey now, if you say it enough times people are going to start getting > ideas ;-P > >> I propose that we fold something like the patch below in instead >> (tested with get-reg-list). > > Agreed, I've backed out my diff and applied yours. Pushed (with force!) > to my repo now, PTAL. > > -- > Thanks, > Oliver > I was so careless that I missed two bugs and failed to test the last version of my patch. It is fortunate that the bugs were caught by careful review though we don't have a strong type system (yet). Your tree looks good to me. Regards, Akihiko Odaki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel