Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1587057iog; Thu, 16 Jun 2022 09:18:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tefMoRkvB8ChH7JK326QpXWXpmCdmCYQDkaRy5bml2zFClx8rZqnyr6SRc5VgjcKNaEjwO X-Received: by 2002:a05:6402:43c5:b0:42d:e4f6:d63e with SMTP id p5-20020a05640243c500b0042de4f6d63emr7428378edc.303.1655396310746; Thu, 16 Jun 2022 09:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655396310; cv=none; d=google.com; s=arc-20160816; b=CX0D1/Moc6OphKXcBrKSUzJmDKV6KW257L2Alc5/dtbJejPGgxjANDzMmCRgUjldIr Oc3sK18rg8fxmMEelzFW1SeMU04HjT94yu30kqtFTrufnq3bemfolp1IGnby1+HSl6lh qyioc9CCOt3fePtwpdqqKRp8uNp3KuTu3rrOpjEf0APl3//tigJbi3PPEgRtEJkxeRds 5Nn/+hkMue3CiSsfdmKXEl52msvzqPmL3MKh+9QhSkoYhSha+1aL6X8/g25hNQApsLxw h1PaTdPIwX9hJvhXq+joG0UA8R7xljqB+th+uUYvpkIq55HXOztrWQNyHTnVkz64b4lJ gAig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=B4Lbd5kL4genrrJrhOvBPEOADWvCq/rTQnj02ARphms=; b=HfIaLdDxqOkROKh7udfW5UH+mEquT40kUDOl416RY0u88GBFkmFOlBPPE7IAU3K72F vITu3yJ0shPNAdIy05Nn7dxtY2LZg4xfpYLoMYUdNgYtyGxLjgXAVbLV4sseCroQJ7LP B7sFZo+DbHtHkCucWLwafXMvAGK7lX0U1pw1DnWigrpcmcGXtl+eJZemw0+qOMCkT5Yz ijf2c/yiLLtWjSUr9HWrkUXRVxAGY767JFWBvvdYJl3moMei3lxjUWKHlJeHot8o+yMt +eAqfoVeDOa2bws4rVwppf6TitPFJUcqYpSRDFIcBjOUJb5Z0wcKjQTbKco0m3iVx/Ry xcNA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l28-20020a50d6dc000000b0042baca38617si2970585edj.89.2022.06.16.09.18.05; Thu, 16 Jun 2022 09:18:30 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377995AbiFPP7B convert rfc822-to-8bit (ORCPT + 99 others); Thu, 16 Jun 2022 11:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377785AbiFPP66 (ORCPT ); Thu, 16 Jun 2022 11:58:58 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BE534132A for ; Thu, 16 Jun 2022 08:58:56 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-127-G5mX8BQ_PnOGd3hJyVz1GQ-1; Thu, 16 Jun 2022 16:58:53 +0100 X-MC-Unique: G5mX8BQ_PnOGd3hJyVz1GQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Thu, 16 Jun 2022 16:58:52 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.036; Thu, 16 Jun 2022 16:58:52 +0100 From: David Laight To: 'Andrew Jones' , Raghavendra Rao Ananta CC: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , "Catalin Marinas" , Will Deacon , "Peter Shier" , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Colton Lewis , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.cs.columbia.edu" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: RE: [PATCH] selftests: KVM: Handle compiler optimizations in ucall Thread-Topic: [PATCH] selftests: KVM: Handle compiler optimizations in ucall Thread-Index: AQHYgXkNkdHi2edO0UOJoWwOrv/ni61SMGPg Date: Thu, 16 Jun 2022 15:58:52 +0000 Message-ID: <33ca91aeb5254831a88e187ff8d9a2c2@AcuMS.aculab.com> References: <20220615185706.1099208-1-rananta@google.com> <20220616120232.ctkekviusrozqpru@gator> In-Reply-To: <20220616120232.ctkekviusrozqpru@gator> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Andrew Jones > Sent: 16 June 2022 13:03 > > On Wed, Jun 15, 2022 at 06:57:06PM +0000, Raghavendra Rao Ananta wrote: > > The selftests, when built with newer versions of clang, is found > > to have over optimized guests' ucall() function, and eliminating > > the stores for uc.cmd (perhaps due to no immediate readers). This > > resulted in the userspace side always reading a value of '0', and > > causing multiple test failures. > > > > As a result, prevent the compiler from optimizing the stores in > > ucall() with WRITE_ONCE(). > > > > Suggested-by: Ricardo Koller > > Suggested-by: Reiji Watanabe > > Signed-off-by: Raghavendra Rao Ananta > > --- > > tools/testing/selftests/kvm/lib/aarch64/ucall.c | 9 ++++----- > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > index e0b0164e9af8..be1d9728c4ce 100644 > > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > @@ -73,20 +73,19 @@ void ucall_uninit(struct kvm_vm *vm) > > > > void ucall(uint64_t cmd, int nargs, ...) > > { > > - struct ucall uc = { > > - .cmd = cmd, > > - }; > > + struct ucall uc = {}; > > va_list va; > > int i; > > > > + WRITE_ONCE(uc.cmd, cmd); > > nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; > > > > va_start(va, nargs); > > for (i = 0; i < nargs; ++i) > > - uc.args[i] = va_arg(va, uint64_t); > > + WRITE_ONCE(uc.args[i], va_arg(va, uint64_t)); > > va_end(va); > > > > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > > + WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&uc); > > } Am I misreading things again? That function looks like it writes the address of an on-stack item into global data. Maybe 'uc' ought to be static? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)