From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8E3FC433DF for ; Tue, 30 Jun 2020 19:40:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF1B120768 for ; Tue, 30 Jun 2020 19:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728240AbgF3Tk0 (ORCPT ); Tue, 30 Jun 2020 15:40:26 -0400 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 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0905CC061755; Tue, 30 Jun 2020 12:40:25 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqM72-002x8g-D9; Tue, 30 Jun 2020 19:40:12 +0000 Date: Tue, 30 Jun 2020 20:40:12 +0100 From: Al Viro To: Linus Torvalds Cc: linux-arch , Linux Kernel Mailing List , David Miller , Tony Luck , Will Deacon Subject: Re: [PATCH 18/41] regset: new method and helpers for it 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 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.