From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965161AbdKGBXM (ORCPT ); Mon, 6 Nov 2017 20:23:12 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50960 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754732AbdKGBXD (ORCPT ); Mon, 6 Nov 2017 20:23:03 -0500 X-Google-Smtp-Source: ABhQp+QHZ7k8eDeFoO3XusYDbnNX/zw9H3C5NNl6Pb+SJsQS1rZuXo2lFrwtaZolQ2w2tgTjKBcxBQ== X-ME-Sender: Date: Tue, 7 Nov 2017 09:24:24 +0800 From: Boqun Feng To: Mathieu Desnoyers Cc: Peter Zijlstra , "Paul E . McKenney" , Andy Lutomirski , Dave Watson , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Subject: Re: [RFC PATCH v10 for 4.15 01/14] Restartable sequences system call Message-ID: <20171107012424.GB6280@tardis> References: <20171106205644.29386-1-mathieu.desnoyers@efficios.com> <20171106205644.29386-2-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Fba/0zbH8Xs+Fj9o" Content-Disposition: inline In-Reply-To: <20171106205644.29386-2-mathieu.desnoyers@efficios.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Fba/0zbH8Xs+Fj9o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 06, 2017 at 03:56:31PM -0500, Mathieu Desnoyers wrote: [...] > + > +/* > + * struct rseq is aligned on 4 * 8 bytes to ensure it is always > + * contained within a single cache-line. > + * > + * A single struct rseq per thread is allowed. > + */ > +struct rseq { > + /* > + * Restartable sequences cpu_id_start field. Updated by the > + * kernel, and read by user-space with single-copy atomicity > + * semantics. Aligned on 32-bit. Always contain a value in the > + * range of possible CPUs, although the value may not be the > + * actual current CPU (e.g. if rseq is not initialized). This > + * CPU number value should always be confirmed against the value > + * of the cpu_id field. > + */ > + uint32_t cpu_id_start; > + /* > + * Restartable sequences cpu_id field. Updated by the kernel, > + * and read by user-space with single-copy atomicity semantics. > + * Aligned on 32-bit. Values -1U and -2U have a special > + * semantic: -1U means "rseq uninitialized", and -2U means "rseq > + * initialization failed". > + */ > + uint32_t cpu_id; > + /* > + * Restartable sequences rseq_cs field. > + * > + * Contains NULL when no critical section is active for the current > + * thread, or holds a pointer to the currently active struct rseq_cs. > + * > + * Updated by user-space at the beginning of assembly instruction > + * sequence block, and by the kernel when it restarts an assembly > + * instruction sequence block, and when the kernel detects that it > + * is preempting or delivering a signal outside of the range > + * targeted by the rseq_cs. Also needs to be cleared by user-space > + * before reclaiming memory that contains the targeted struct > + * rseq_cs. > + * > + * Read and set by the kernel with single-copy atomicity semantics. > + * Aligned on 64-bit. > + */ > + RSEQ_FIELD_u32_u64(rseq_cs); > + /* > + * - RSEQ_DISABLE flag: > + * > + * Fallback fast-track flag for single-stepping. > + * Set by user-space if lack of progress is detected. > + * Cleared by user-space after rseq finish. > + * Read by the kernel. > + * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT > + * Inhibit instruction sequence block restart and event > + * counter increment on preemption for this thread. Nit: "event counter" has been removed entirely ;-) > + * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL > + * Inhibit instruction sequence block restart and event > + * counter increment on signal delivery for this thread. > + * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE > + * Inhibit instruction sequence block restart and event > + * counter increment on migration for this thread. > + */ > + uint32_t flags; > +} __attribute__((aligned(4 * sizeof(uint64_t)))); > + > +#endif /* _UAPI_LINUX_RSEQ_H */ [...] > + } else { > + /* > + * If there was no rseq previously registered, > + * we need to ensure the provided rseq is > + * properly aligned and valid. > + */ > + if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) > + || rseq_len != sizeof(*rseq)) > + return -EINVAL; > + if (!access_ok(VERIFY_WRITE, rseq, rseq_len)) > + return -EFAULT; > + current->rseq = rseq; > + current->rseq_len = rseq_len; > + current->rseq_sig = sig; > + /* > + * If rseq was previously inactive, and has just > + * been registered, ensure the cpu_id and > + * event_counter fields are updated before s/event_counter/cpu_start_id/ ? Regards, Boqun > + * returning to user-space. > + */ > + rseq_set_notify_resume(current); > + } > + > + return 0; > +} [...] --Fba/0zbH8Xs+Fj9o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAloBCzAACgkQSXnow7UH +rh5kgf8DdscO+BkvEsWLYd8FuiBt/DjH9XFZ5iIorgkJvhlYcIHbosUFgbAsnu8 ZG8Fj0/DUW6Av51/29qu/9SzZ0e0MWRQ2L6sRLH9k9mTrq0YZ+xEEdLMCUMSiovG 9tbizablJHA1DzahbYk/U7o2keEv9ov3zuFL73X+7AW4p7IAAPa5/a10CYki3nV/ ppO2L8gb/FkPIExOtgB59X9jmwnWTcMoLx5z+eg6ioIa4TfWWdkGriOr/3ddn3Vv gwRqyKsbdDsZ329WYlJfINP0bezH9vgQz6hKTzlPcOER6pURG+Ji7qiQpuiRJeHi 1kBH4GC4ap92TrSThcA8yLQdqgc55Q== =rM6n -----END PGP SIGNATURE----- --Fba/0zbH8Xs+Fj9o-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boqun Feng Subject: Re: [RFC PATCH v10 for 4.15 01/14] Restartable sequences system call Date: Tue, 7 Nov 2017 09:24:24 +0800 Message-ID: <20171107012424.GB6280@tardis> References: <20171106205644.29386-1-mathieu.desnoyers@efficios.com> <20171106205644.29386-2-mathieu.desnoyers@efficios.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Fba/0zbH8Xs+Fj9o" Return-path: Content-Disposition: inline In-Reply-To: <20171106205644.29386-2-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org To: Mathieu Desnoyers Cc: Peter Zijlstra , "Paul E . McKenney" , Andy Lutomirski , Dave Watson , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon List-Id: linux-api@vger.kernel.org --Fba/0zbH8Xs+Fj9o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 06, 2017 at 03:56:31PM -0500, Mathieu Desnoyers wrote: [...] > + > +/* > + * struct rseq is aligned on 4 * 8 bytes to ensure it is always > + * contained within a single cache-line. > + * > + * A single struct rseq per thread is allowed. > + */ > +struct rseq { > + /* > + * Restartable sequences cpu_id_start field. Updated by the > + * kernel, and read by user-space with single-copy atomicity > + * semantics. Aligned on 32-bit. Always contain a value in the > + * range of possible CPUs, although the value may not be the > + * actual current CPU (e.g. if rseq is not initialized). This > + * CPU number value should always be confirmed against the value > + * of the cpu_id field. > + */ > + uint32_t cpu_id_start; > + /* > + * Restartable sequences cpu_id field. Updated by the kernel, > + * and read by user-space with single-copy atomicity semantics. > + * Aligned on 32-bit. Values -1U and -2U have a special > + * semantic: -1U means "rseq uninitialized", and -2U means "rseq > + * initialization failed". > + */ > + uint32_t cpu_id; > + /* > + * Restartable sequences rseq_cs field. > + * > + * Contains NULL when no critical section is active for the current > + * thread, or holds a pointer to the currently active struct rseq_cs. > + * > + * Updated by user-space at the beginning of assembly instruction > + * sequence block, and by the kernel when it restarts an assembly > + * instruction sequence block, and when the kernel detects that it > + * is preempting or delivering a signal outside of the range > + * targeted by the rseq_cs. Also needs to be cleared by user-space > + * before reclaiming memory that contains the targeted struct > + * rseq_cs. > + * > + * Read and set by the kernel with single-copy atomicity semantics. > + * Aligned on 64-bit. > + */ > + RSEQ_FIELD_u32_u64(rseq_cs); > + /* > + * - RSEQ_DISABLE flag: > + * > + * Fallback fast-track flag for single-stepping. > + * Set by user-space if lack of progress is detected. > + * Cleared by user-space after rseq finish. > + * Read by the kernel. > + * - RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT > + * Inhibit instruction sequence block restart and event > + * counter increment on preemption for this thread. Nit: "event counter" has been removed entirely ;-) > + * - RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL > + * Inhibit instruction sequence block restart and event > + * counter increment on signal delivery for this thread. > + * - RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE > + * Inhibit instruction sequence block restart and event > + * counter increment on migration for this thread. > + */ > + uint32_t flags; > +} __attribute__((aligned(4 * sizeof(uint64_t)))); > + > +#endif /* _UAPI_LINUX_RSEQ_H */ [...] > + } else { > + /* > + * If there was no rseq previously registered, > + * we need to ensure the provided rseq is > + * properly aligned and valid. > + */ > + if (!IS_ALIGNED((unsigned long)rseq, __alignof__(*rseq)) > + || rseq_len != sizeof(*rseq)) > + return -EINVAL; > + if (!access_ok(VERIFY_WRITE, rseq, rseq_len)) > + return -EFAULT; > + current->rseq = rseq; > + current->rseq_len = rseq_len; > + current->rseq_sig = sig; > + /* > + * If rseq was previously inactive, and has just > + * been registered, ensure the cpu_id and > + * event_counter fields are updated before s/event_counter/cpu_start_id/ ? Regards, Boqun > + * returning to user-space. > + */ > + rseq_set_notify_resume(current); > + } > + > + return 0; > +} [...] --Fba/0zbH8Xs+Fj9o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAloBCzAACgkQSXnow7UH +rh5kgf8DdscO+BkvEsWLYd8FuiBt/DjH9XFZ5iIorgkJvhlYcIHbosUFgbAsnu8 ZG8Fj0/DUW6Av51/29qu/9SzZ0e0MWRQ2L6sRLH9k9mTrq0YZ+xEEdLMCUMSiovG 9tbizablJHA1DzahbYk/U7o2keEv9ov3zuFL73X+7AW4p7IAAPa5/a10CYki3nV/ ppO2L8gb/FkPIExOtgB59X9jmwnWTcMoLx5z+eg6ioIa4TfWWdkGriOr/3ddn3Vv gwRqyKsbdDsZ329WYlJfINP0bezH9vgQz6hKTzlPcOER6pURG+Ji7qiQpuiRJeHi 1kBH4GC4ap92TrSThcA8yLQdqgc55Q== =rM6n -----END PGP SIGNATURE----- --Fba/0zbH8Xs+Fj9o--