From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [PATCH 18/41] regset: new method and helpers for it Date: Tue, 30 Jun 2020 20:40:12 +0100 Message-ID: <20200630194012.GH2786714@ZenIV.linux.org.uk> References: <20200629182349.GA2786714@ZenIV.linux.org.uk> <20200629182628.529995-1-viro@ZenIV.linux.org.uk> <20200629182628.529995-18-viro@ZenIV.linux.org.uk> <20200629203028.GB2786714@ZenIV.linux.org.uk> <20200630132508.GF2786714@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727104AbgF3Tk0 (ORCPT ); Tue, 30 Jun 2020 15:40:26 -0400 Content-Disposition: inline In-Reply-To: Sender: linux-arch-owner@vger.kernel.org List-ID: To: Linus Torvalds Cc: linux-arch , Linux Kernel Mailing List , David Miller , Tony Luck , Will Deacon On Tue, Jun 30, 2020 at 09:53:12AM -0700, Linus Torvalds wrote: > On Tue, Jun 30, 2020 at 6:25 AM Al Viro wrote: > > > > How about ->regset_get()? > > Sounds good to me. And if you ever do something similar for 'set', you > have a natural name to pick. Umm... Something similar for 'set' would, AFAICS, work reasonably well with the following primitives. membuf_read(&from, data, size) -- copy min(size, amount left) membuf_fetch(&from, data) -- copy min(sizeof(data), amount left) into data (obviously a macro) membuf_skip(&from, size) -- obvious membuf_pick(&from, size), along the lines of if (unlikely(size > p->left) return ERR_PTR(-EINVAL); res = p->p; p->p += size; p->left -= size; return res; So it would be something like int regset_tls_set(struct task_struct *target, const struct user_regset *regset, struct membuf from) { const struct user_desc *info; int n = from.left / sizeof(*info); int i; info = membuf_pick(&from, n * sizeof(*info)); // can't fail here for (i = 0; i < n; i++) if (!tls_desc_okay(info + i)) return -EINVAL; set_tls_desc(target, GDT_ENTRY_TLS_MIN, info, n); return 0; } and static int genregs32_set(struct task_struct *target, const struct user_regset *regset, struct membuf from) { int err; unsigned pos, v; for (pos = 0; from.left; pos += sizeof(u32)) { membuf_fetch(&from, v); err = putreg32(target, pos, v); if (err) return err; } return 0; } or /* * Copy the supplied 64-bit NT_MIPS_DSP buffer to the DSP context. */ static int dsp64_set(struct task_struct *target, const struct user_regset *regset, struct membuf from) { if (!cpu_has_dsp) return -EIO; membuf_read(&from, target->thread.dsp.dspr, NUM_DSP_REGS * sizeof(u64)); return membuf_read(&from, target->thread.dsp.dspcontrol, sizeof(u64)); } etc.