Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2451870pxa; Fri, 7 Aug 2020 11:26:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfKIACm/2QvV5HE3aHebvz0iK7NmKbqUerKSXcgUI7oIPWvdkhVsVNJDnyYJDBJfAHMuqj X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr10246010ejw.92.1596824781902; Fri, 07 Aug 2020 11:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596824781; cv=none; d=google.com; s=arc-20160816; b=fgAqukBHS50bik3yeAA2B4SMsP9be6A9pcLGkjYBVnT+qciaqTpasSRns4nrEmlebw AnxQd4W0t6J1cOSFV/po3nlhHtISAGg2i8EJBHXoQh6jmPzLqs8BfBj0ccqtA4yVC3a5 0s42Vta0RdWZgjodBGnx25bPFW0W8yux63Im6/SgeuHSzyi8H4qQ9wEWRX/ZDfE1CAFB zNpzIZfGrhZSaq175tm1YJqMGVjsy5stHk5YO+JzI8aEu6kKTj16JCKFogD7PL/HU4oo pVMWtRa1R71Sb5Q50UzZW4IL+sKNXXWnR+giz82V7EPVIl6nhFaLYYfG1NfE9A2WE6OA r41Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=Fk7L47iTkSwZpfKYXHhMx/3iZW27NHUzuAWcFK9emjY=; b=oVzOTKBHdAtF/UWLTQqMY9DUIw8o7GIPcLZ77LztxL9i2PJdxuC6o17jkJ29SoIkHY NK6LdMl0ZNX/dtYRspuXRgQ1JM/XJNhSJd7inq5Tr+WSbFYqMJiACRPzmbZZWL2p2so2 q1OZ+Dedc8YyR7SIw0HXATN3/Ywb0HXBwMeFhf/wolJQZdkpq9nGmcylA+s6SxVsumWA ZSsyPyfv6qk2OqLZ8RvhK/dO/K/aYdMFJzAK/DVypQGLr/FQgXKYBI07eseMepKbwIXt qZzjkttsFEwr2Q8fwYWU7qQrBNDyrk1D0CQ2mLNTCAr7hwhgrSHoaHHfO7149++FYZN6 6T3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=jX0++gUu; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si1296892ejf.672.2020.08.07.11.25.57; Fri, 07 Aug 2020 11:26:21 -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=@efficios.com header.s=default header.b=jX0++gUu; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726096AbgHGSZR (ORCPT + 99 others); Fri, 7 Aug 2020 14:25:17 -0400 Received: from mail.efficios.com ([167.114.26.124]:34046 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbgHGSZR (ORCPT ); Fri, 7 Aug 2020 14:25:17 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2C2172C5413; Fri, 7 Aug 2020 14:25:16 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id xA9g-c6Pskj9; Fri, 7 Aug 2020 14:25:15 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id DDAB22C5412; Fri, 7 Aug 2020 14:25:15 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com DDAB22C5412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1596824715; bh=Fk7L47iTkSwZpfKYXHhMx/3iZW27NHUzuAWcFK9emjY=; h=Date:From:To:Message-ID:MIME-Version; b=jX0++gUubwjvR8YKjXX6OXk4Ub+pQP9clE12B+bHSzYzElYrbvKeJO6RCDnAWP723 I238ewjAMDukclMZpxs3UfGTGCpgm/VvZTOSLa2vWPIDsUsZ9hEM7Pb02TTZg84OHS YGmX3bwrB+mcxOFPPd3NiKsMK5GP7rW4Qz9urorlllU9VBbmTgxVDQbBnp4L1OL314 a6kn1q6q06NmodgL3q5s2LrNZ16JbIptHDrMsDc0aggzR/4MLYRLwf35nK83ScIQSJ DU9Vw3jE+6SK1Z37f3i2auAusKi7T8e632I66NkaxiXTo9pb+ACMW7DkbBS3pqT+TL GeZDz0Q75Komg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id KFo8OEDB8er2; Fri, 7 Aug 2020 14:25:15 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id CABDE2C4E6F; Fri, 7 Aug 2020 14:25:15 -0400 (EDT) Date: Fri, 7 Aug 2020 14:25:15 -0400 (EDT) From: Mathieu Desnoyers To: Peter Oskolkov Cc: Boqun Feng , Peter Oskolkov , paulmck , Peter Zijlstra , linux-kernel , Paul Turner , Chris Kennelly Message-ID: <1745833987.2640.1596824715742.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20200806170544.382140-1-posk@google.com> <20200806170544.382140-2-posk@google.com> <20200807002705.GA889@tardis> Subject: Re: [PATCH 2/2 v2] rseq/selftests: test MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3959 (ZimbraWebClient - FF79 (Linux)/8.8.15_GA_3953) Thread-Topic: rseq/selftests: test MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU Thread-Index: wGhwrykpufytkyWLEFxWHunBY+rpvQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Aug 7, 2020, at 1:55 PM, Peter Oskolkov posk@posk.io wrote: > On Thu, Aug 6, 2020 at 5:27 PM Boqun Feng wrote: [...] >> What if the manager thread update ->percpu_list_ptr and call >> membarrier() here? I.e. >> >> CPU0 CPU1 >> list_ptr = atomic_load(&args->percpu_list_ptr); // read list_b >> >> atomic_store(&args->percpu_list_ptr, list_a); >> sys_membarrier(MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU, 1); // send ipi to >> restart rseq.cs on CPU1 >> >> >> cpu = rseq_cpu_start(); // start a rseq.cs and accessing list_b! >> >> The thing is, atomic_load() is an reference to ->percpu_list_ptr, which >> is outside the rseq.cs, simply restarting rseq doesn't kill this >> reference. >> >> Am I missing something subtle? > > rseq_cmpeqv_cmpeqv_store is used below to make sure the reference is > the one that should be used; if it is no longer "active", the > iteration is restarted. I suspect it "works" because the manager thread does not free and repurpose the memory where list_a is allocated, nor does it store to its list head (which would corrupt the pointer dereferenced by CPU 1 in the scenario above). This shares similarities with type-safe memory allocation (see SLAB_TYPESAFE_BY_RCU). Even though it is not documented as such (or otherwise) in the example code, I feel this example looks like it guarantees that the manager thread "owns" list_a after the rseq-fence, when in fact it can still be read by the rseq critical sections. AFAIU moving the atomic_load(&args->percpu_list_ptr) into the critical section should entirely solve this and guarantee exclusive access to the old list after the manager's rseq-fence. I wonder why this simpler approach is not favored ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com