Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4415315rwb; Sat, 21 Jan 2023 11:24:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsYMTc3VcF4HnRkRn/1+jA6TKftflrkUe36/gosiL+F2aB6oGRY8WvaxlawBEwLG6b+OA0m X-Received: by 2002:a05:6a20:d045:b0:b6:90bd:f44e with SMTP id hv5-20020a056a20d04500b000b690bdf44emr21657986pzb.49.1674329040444; Sat, 21 Jan 2023 11:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674329040; cv=none; d=google.com; s=arc-20160816; b=Tm0uP/9tmP3jrxmOBE+0DLcYqTi22dyY0e3yqNxdmxztqWgOIAUfHMAD4fIgLH7K+D hHM6ZEuVtxC3NgEZ6WsR613HpYkQxf9YqJ33ku54FXf409aL11O+Kz1Q/37C/yVsiu9C ZSDqFCPuTP9WSuiVj5Kwbr/SWTL+cLK5GUE9gFo2gaim0h8hHZrCoBSFFeRlAZLJfHbC YmnpAEizoni2sHgY1CHUTnwmqZFVXYEfcAXkvBy2UcQLJ1P+1jDzPWw/0XqPwru4IgZz xonz0aYbbYcNk3uXjD5jYj21/amvu1ZiczLJM1JaBBvk8zK8YPN6h6cLO3ERSqd2JCaX ydKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=YSLV8t+mHMg9bRk9e6jbKy2QqL7MoxPyHgIADPLc1gw=; b=ZOVDN4s49/67uW1WLkxJ3WRzUoSc5LGeqqCQPi7u+HfRsjX9Oz6OPk042KD/fLv8wv yyk5GbWrCnyk24qWgP0j4mfCgelDq2Snnk/KFRdn+VaWpWmWWgsFZHVTwQaYRHocTnGc K96j298cLatZHktOVtQpgaW3k9vy31tlYlguTnH9SzbhsCwadDe58SBYGxuy4EanRbTM NQ+/+pmolCWLYWVKhIxxtAvxeHV+kC+xbkXAQb7kUjWOO91e9NofGi+raUGKm8TTr6g+ /OjY/0G/p6FWS6ovAtNiai1rCkc/xthLMQlCWEOrkTNsP5OLTa2BM+UCsZdXEESZAsOk lokQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oBvdKsRB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a63d30b000000b0047875582864si48301880pgg.263.2023.01.21.11.23.54; Sat, 21 Jan 2023 11:24:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oBvdKsRB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjAUSPd (ORCPT + 50 others); Sat, 21 Jan 2023 13:15:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjAUSPb (ORCPT ); Sat, 21 Jan 2023 13:15:31 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A85D92B627 for ; Sat, 21 Jan 2023 10:15:30 -0800 (PST) Date: Sat, 21 Jan 2023 18:15:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1674324928; 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=YSLV8t+mHMg9bRk9e6jbKy2QqL7MoxPyHgIADPLc1gw=; b=oBvdKsRBk/KCPvMNqQzp8o87W6yFujl67ZzxL8++ppyZmPdtkHvA2GFp99B8TDvnTVdeQh pWJyS0yCDMpYHvIhdVFpXa6IkFr0EtYQtAtWmeVisBYHjdhKdersuNwplMQo49DHGaQyYa dU2lu1ZuNy6fwOjs8GaspLV05q18rQQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: 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 Subject: Re: [PATCH v7 7/7] KVM: arm64: Normalize cache configuration Message-ID: References: <20230112023852.42012-1-akihiko.odaki@daynix.com> <20230112023852.42012-8-akihiko.odaki@daynix.com> <86k01gm6ys.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86k01gm6ys.wl-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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