From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EA63198A36 for ; Mon, 20 Jan 2025 22:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737411778; cv=none; b=h4/CYVFgOh/yPSs9GYWOQxPeVXSYSxTDmhsT3XMC//PjiKN+apIAkSK9OXSGdcs11zXL6kL/7fdIy8m6FwT0OlkGaHCpMvZcaLxpJQPlCYCInUUdShiTPWrMYBy48FC3Qvav5ZfYWw2RGnEOKCnJvApKhBso5OLxoE03srXyrA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737411778; c=relaxed/simple; bh=IfYlyCUdXbN0ePe2rA+WzjYBPrVGFvawdPIa/UaQCyE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PSzIVAFdcUgHCTMHxVamioIRGl+fqXbI72VVe5irz6W417imIqgFZSo3cZxRrevXvmQ1etZv6Ynwh/rNUlnyT+Z/C5FlWxeQV009CakND51wcOKKGypSYY3+E3D+7C5qNSc/d/nY9VbmPatekMDWQvyscqKyRxAYucKNVK6WVPk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=ew5yEgc1; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ew5yEgc1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1737411773; bh=IfYlyCUdXbN0ePe2rA+WzjYBPrVGFvawdPIa/UaQCyE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ew5yEgc1S0gVvEdwjAH7c5tE58tAzQBqWpELRGvIRuynizn5nI90PrqkG4wDNMCWg ZjpKcB9YKy7Qr4H6bkqC2QqAs05H/MEj7vtSM/M4FCn76ZhxECBsvUVKoFdfHmx3g7 gCjUgh11Bz7tin2y7v7LLgp7T6bzRm2x+3o6U4n4= Date: Mon, 20 Jan 2025 23:22:52 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Cyrill Gorcunov Cc: LKML , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner Subject: Re: [PATCH] posix-clock: drop code duplication using compat_ptr_ioctl Message-ID: <4229b992-77ef-404d-b045-8f1ccad1035a@t-8ch.de> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Cyrill, On 2025-01-21 01:10:27+0300, Cyrill Gorcunov wrote: > The posix_clock_compat_ioctl() is just a clone of posix_clock_ioctl(), > drop the redundance. > > Signed-off-by: Cyrill Gorcunov > Cc: Anna-Maria Behnsen > Cc: Frederic Weisbecker > Cc: Thomas Gleixner > --- > kernel/time/posix-clock.c | 24 +----------------------- > 1 file changed, 1 insertion(+), 23 deletions(-) > > Index: linux-tip.git/kernel/time/posix-clock.c > =================================================================== > --- linux-tip.git.orig/kernel/time/posix-clock.c > +++ linux-tip.git/kernel/time/posix-clock.c > @@ -90,26 +90,6 @@ static long posix_clock_ioctl(struct fil > return err; > } > > -#ifdef CONFIG_COMPAT > -static long posix_clock_compat_ioctl(struct file *fp, > - unsigned int cmd, unsigned long arg) > -{ > - struct posix_clock_context *pccontext = fp->private_data; > - struct posix_clock *clk = get_posix_clock(fp); > - int err = -ENOTTY; > - > - if (!clk) > - return -ENODEV; > - > - if (clk->ops.ioctl) > - err = clk->ops.ioctl(pccontext, cmd, arg); > - > - put_posix_clock(clk); > - > - return err; > -} > -#endif > - > static int posix_clock_open(struct inode *inode, struct file *fp) > { > int err; > @@ -173,9 +153,7 @@ static const struct file_operations posi > .unlocked_ioctl = posix_clock_ioctl, > .open = posix_clock_open, > .release = posix_clock_release, > -#ifdef CONFIG_COMPAT > - .compat_ioctl = posix_clock_compat_ioctl, > -#endif > + .compat_ioctl = compat_ptr_ioctl, This is not correct on s390. (It wasn't before either, though) The improved patch below is in my personal queue, but I didn't get around to actually testing and submitting it yet. > }; > > int posix_clock_register(struct posix_clock *clk, struct device *dev) >From 9d59a26da95ad416710c152dc87ee41f08933c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 3 Jan 2025 18:04:56 +0100 Subject: [PATCH] posix-clock: Fix compat ioctls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pointer arguments passed to ioctls need to pass through compat_ptr() to work correctly on s390; as explained in Documentation/driver-api/ioctl.rst. Plumb the compat_ioctl callback through 'struct posix_clock_operations' and handle the different ioctls cmds in the new ptp_compat_ioctl(). Fixes: 0606f422b453 ("posix clocks: Introduce dynamic clocks") Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh --- drivers/ptp/ptp_chardev.c | 18 ++++++++++++++++++ drivers/ptp/ptp_clock.c | 1 + drivers/ptp/ptp_private.h | 7 +++++++ include/linux/posix-clock.h | 3 +++ kernel/time/posix-clock.c | 4 ++-- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index ea96a14d72d1..704af620c117 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -4,6 +4,7 @@ * * Copyright (C) 2010 OMICRON electronics GmbH */ +#include #include #include #include @@ -507,6 +508,23 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, return err; } +#ifdef CONFIG_COMPAT +long ptp_compat_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, + unsigned long arg) +{ + switch (cmd) { + case PTP_ENABLE_PPS: + case PTP_ENABLE_PPS2: + /* These take in scalar arg, do not convert */ + break; + default: + arg = (unsigned long)compat_ptr(arg); + } + + return ptp_ioctl(pccontext, cmd, arg); +} +#endif + __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp, poll_table *wait) { diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 77a36e7bddd5..dec84b81cedf 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -180,6 +180,7 @@ static struct posix_clock_operations ptp_clock_ops = { .clock_getres = ptp_clock_getres, .clock_settime = ptp_clock_settime, .ioctl = ptp_ioctl, + .compat_ioctl = ptp_compat_ioctl, .open = ptp_open, .release = ptp_release, .poll = ptp_poll, diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index 18934e28469e..13999a7af47a 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -133,6 +133,13 @@ int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin, long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, unsigned long arg); +#ifdef CONFIG_COMPAT +long ptp_compat_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, + unsigned long arg); +#else +#define ptp_compat_ioctl NULL +#endif + int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode); int ptp_release(struct posix_clock_context *pccontext); diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h index ef8619f48920..8bdc7aec5f79 100644 --- a/include/linux/posix-clock.h +++ b/include/linux/posix-clock.h @@ -54,6 +54,9 @@ struct posix_clock_operations { long (*ioctl)(struct posix_clock_context *pccontext, unsigned int cmd, unsigned long arg); + long (*compat_ioctl)(struct posix_clock_context *pccontext, unsigned int cmd, + unsigned long arg); + int (*open)(struct posix_clock_context *pccontext, fmode_t f_mode); __poll_t (*poll)(struct posix_clock_context *pccontext, struct file *file, diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c index 1af0bb2cc45c..63184d92ef13 100644 --- a/kernel/time/posix-clock.c +++ b/kernel/time/posix-clock.c @@ -101,8 +101,8 @@ static long posix_clock_compat_ioctl(struct file *fp, if (!clk) return -ENODEV; - if (clk->ops.ioctl) - err = clk->ops.ioctl(pccontext, cmd, arg); + if (clk->ops.compat_ioctl) + err = clk->ops.compat_ioctl(pccontext, cmd, arg); put_posix_clock(clk);