Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2329108pxb; Mon, 19 Apr 2021 03:12:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9nztuGJ0LD0X/Zky5Rm32kKaRM0T2fvlr6o2tHk23chVSxeseb2FAABTyA7Tam4tykhDe X-Received: by 2002:a05:6402:142:: with SMTP id s2mr24555989edu.2.1618827122744; Mon, 19 Apr 2021 03:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618827122; cv=none; d=google.com; s=arc-20160816; b=hIjCxMq7/4UtmGQjy5X1VMvolkMiLhe/TWszyzqaysPFyehQHxAkdltiTOxVaAilGM e8K4cVcRNvBwuD4CGiRQp8Tyq/U/LQ+jionCfzE/fuNgJNqospEfDv90g8cwdvMrfJE0 OVudr8MZ0zPT/KkKwcSgNDVOBdJSASYy6FL8QjZbH2E5bN2ZcjA+B0QEruAjnTNZ2UhR Lc83KRXTwPkmJ5xOn84B/cQVhmEWq22s4iEPACdn3Vttj3MxjHinn1yvtwSnpEFq0lmG Wez/S2WcZHcuRpZu3hduBr7EL2US3NsdhA4RZFg/+znpgoDg0bmryeYGDK9/2/fxWZG7 1GhQ== 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 :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=ee0dIEYIH6BtGJdamgCFF0WqtWy7bMaej2BcD7VK7sE=; b=vLUjXwjVKIHo2+tka8hWu2phEgYIffFymcjazGlJrqPjuHRCFMzKv0xvX7VM3xX1q/ ddcgNHUJ0ouCAUl5cMZ/mdpv9TQHEwoUpGEiuQOB+bUEUOdrQ7AvrBbXAROmfATNB5wB 9Fe4BtrBDORl/w4PprpFnRxsNIRcD89Zqef356Sg7jA9yXbPTykKFPr2VHUTXBGtkQzS kCp1RRMPDVg/rOTdgVaJdm2pfzjyrHjTWJgxCtfgjoNNVskfGOyEK55z4d0xAtuK2zSj Wa73moyamqFP6VEVzSXY1Fz7u0uJmec1Rn7n0spNoWRh5rc+2sDy0UGIGOfHG1kg4ti0 ng9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WEG/9CJu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si12035419ejf.662.2021.04.19.03.11.39; Mon, 19 Apr 2021 03:12:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="WEG/9CJu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238392AbhDSJCt (ORCPT + 99 others); Mon, 19 Apr 2021 05:02:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47492 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237627AbhDSJCs (ORCPT ); Mon, 19 Apr 2021 05:02:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822939; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ee0dIEYIH6BtGJdamgCFF0WqtWy7bMaej2BcD7VK7sE=; b=WEG/9CJuP5TZRWL7WgKVDYd9KZgfr+XVyuVngCU9DlZzydvX7Cn0l5HwHv4tId8Vxv1dQm RiSi4wsAeLYYCFNeA4KDq2tMa/XH/pX4uPH5+YIxRqx8O52/4MdiGpUL4ULoXlN1+ZiGZn rTiPlVmQCeDKUyKeFDYbZd5+o85peKE= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-q6yih9f_PxaNGoYY2mkC6w-1; Mon, 19 Apr 2021 05:02:15 -0400 X-MC-Unique: q6yih9f_PxaNGoYY2mkC6w-1 Received: by mail-ed1-f71.google.com with SMTP id bf25-20020a0564021a59b0290385169cebf8so3410715edb.8 for ; Mon, 19 Apr 2021 02:02:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ee0dIEYIH6BtGJdamgCFF0WqtWy7bMaej2BcD7VK7sE=; b=GraT7mq6SysRZYPb82tqe97ez9pcpiwIe2/YLmSDWZJlFtG3tvvVG3OuGt+kPnec7J nlBVI1pOi4Qs66mM3UgPVCACP3yfqfUNXyaRGh1qZXfpfd0LjiOSIDW9PhvwOda++JCQ 43BB9PgmrlWioLnIW4R0PP0rKCAXFKwClu9aeVsygA72hmVIIdozfCB1fwIs2xlE6P1j X/VGEXAEihps11G/9BBw07fSShg1NeA4M4rGRT9dUU3toP+K/blkEGMoNVgnGNfUH6TF mIjuCP6EN1RLfFYxuoFUwaxGKsku1HoZlXxNfctLSk2dbPuHOSQNH4FZjMo9qb4X1P9o eQKQ== X-Gm-Message-State: AOAM530sHIxNQ9zlgzwsYwVazM2sF+flG47yLp6UqDxnHGEd/PQHQc3g ag7/w/odCgmXFNOJi0i63ff93K7vR33C7Av4M/+kxDvYNjhVDwC2dTNbZOUtTYwAmQW1l4kW58X wwmaHZd6xOcvtR+ZqlWVhd/5J X-Received: by 2002:a17:906:c04:: with SMTP id s4mr14194084ejf.410.1618822934278; Mon, 19 Apr 2021 02:02:14 -0700 (PDT) X-Received: by 2002:a17:906:c04:: with SMTP id s4mr14194067ejf.410.1618822934103; Mon, 19 Apr 2021 02:02:14 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id mj7sm9853549ejb.39.2021.04.19.02.02.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Apr 2021 02:02:13 -0700 (PDT) To: Peter Zijlstra Cc: Wedson Almeida Filho , ojeda@kernel.org, Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon References: <20210414184604.23473-1-ojeda@kernel.org> <7287eac3-f492-bab1-9ea8-b89ceceed560@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH 00/13] [RFC] Rust support Message-ID: <3a874b15-5c21-9ed9-e5c3-995f915cba79@redhat.com> Date: Mon, 19 Apr 2021 11:02:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/04/21 10:26, Peter Zijlstra wrote: > On Mon, Apr 19, 2021 at 09:53:06AM +0200, Paolo Bonzini wrote: >> On 19/04/21 09:32, Peter Zijlstra wrote: >>> On Sat, Apr 17, 2021 at 04:51:58PM +0200, Paolo Bonzini wrote: >>>> On 16/04/21 09:09, Peter Zijlstra wrote: >>>>> Well, the obvious example would be seqlocks. C11 can't do them >>>> >>>> Sure it can. C11 requires annotating with (the equivalent of) READ_ONCE all >>>> reads of seqlock-protected fields, but the memory model supports seqlocks >>>> just fine. >>> >>> How does that help? >>> >>> IIRC there's two problems, one on each side the lock. On the write side >>> we have: >>> >>> seq++; >>> smp_wmb(); >>> X = r; >>> Y = r; >>> smp_wmb(); >>> seq++; >>> >>> Which C11 simply cannot do right because it does't have wmb. >> >> It has atomic_thread_fence(memory_order_release), and >> atomic_thread_fence(memory_order_acquire) on the read side. > > https://godbolt.org/z/85xoPxeE5 > > void writer(void) > { > atomic_store_explicit(&seq, seq+1, memory_order_relaxed); > atomic_thread_fence(memory_order_acquire); This needs to be memory_order_release. The only change in the resulting assembly is that "dmb ishld" becomes "dmb ish", which is not as good as the "dmb ishst" you get from smp_wmb() but not buggy either. The read side can use "dmb ishld" so it gets the same code as Linux. LWN needs a "C11 memory model for kernel folks" article. In the meanwhile there is http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0124r4.html which is the opposite (Linux kernel memory model for C11 folks). Paolo > > X = 1; > Y = 2; > > atomic_store_explicit(&seq, seq+1, memory_order_release); > } > > gives: > > writer: > adrp x1, .LANCHOR0 > add x0, x1, :lo12:.LANCHOR0 > ldr w2, [x1, #:lo12:.LANCHOR0] > add w2, w2, 1 > str w2, [x0] > dmb ishld > ldr w1, [x1, #:lo12:.LANCHOR0] > mov w3, 1 > mov w2, 2 > stp w3, w2, [x0, 4] > add w1, w1, w3 > stlr w1, [x0] > ret > > Which, afaict, is completely buggered. What it seems to be doing is > turning the seq load into a load-acquire, but what we really need is to > make sure the seq store (increment) is ordered before the other stores. > >