[RFC PATCH 3/3] powerpc64/bpf: Add support for bpf trampolines
Add support for bpf_arch_text_poke() and arch_prepare_bpf_trampoline() for powerpc64 -mprofile-kernel. We set aside space for two stubs at the beginning of each bpf program. These stubs are used if having to branch to locations outside the range of a branch instruction. BPF Trampolines adhere to the powerpc64 -mprofile-kernel ABI since these need to attach to ftrace locations using ftrace direct attach. Due to this, bpf_arch_text_poke() patches two instructions: 'mflr r0' and 'bl' for BPF_MOD_CALL. The trampoline code itself closely follows the x86 implementation. Signed-off-by: Naveen N. Rao --- arch/powerpc/net/bpf_jit.h| 8 + arch/powerpc/net/bpf_jit_comp.c | 5 +- arch/powerpc/net/bpf_jit_comp64.c | 619 +- 3 files changed, 630 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h index 0832235a274983..777b10650678af 100644 --- a/arch/powerpc/net/bpf_jit.h +++ b/arch/powerpc/net/bpf_jit.h @@ -19,6 +19,14 @@ #define FUNCTION_DESCR_SIZE0 #endif +#ifdef PPC64_ELF_ABI_v2 +#define BPF_TRAMP_STUB_SIZE32 +#else +#define BPF_TRAMP_STUB_SIZE0 +#endif + +#define PPC_BPF_MAGIC()(0xeB9FC0DE) + #define PLANT_INSTR(d, idx, instr) \ do { if (d) { (d)[idx] = instr; } idx++; } while (0) #define EMIT(instr)PLANT_INSTR(image, ctx->idx, instr) diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index 635f7448ff7952..5df2f15bfe4d75 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -220,7 +220,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) extable_len = fp->aux->num_exentries * sizeof(struct exception_table_entry); proglen = cgctx.idx * 4; - alloclen = proglen + FUNCTION_DESCR_SIZE + fixup_len + extable_len; + alloclen = proglen + FUNCTION_DESCR_SIZE + fixup_len + extable_len + BPF_TRAMP_STUB_SIZE * 2; bpf_hdr = bpf_jit_binary_alloc(alloclen, , 4, bpf_jit_fill_ill_insns); if (!bpf_hdr) { @@ -228,6 +228,8 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) goto out_addrs; } + image += BPF_TRAMP_STUB_SIZE * 2; + if (extable_len) fp->aux->extable = (void *)image + FUNCTION_DESCR_SIZE + proglen + fixup_len; @@ -251,6 +253,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) } /* Code generation passes 1-2 */ + *(code_base - 1) = PPC_BPF_MAGIC(); for (pass = 1; pass < 3; pass++) { /* Now build the prologue, body code & epilogue for real. */ cgctx.idx = 0; diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index c3cfe1f4338fca..20d8f6e3cc9bb0 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,10 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx) { int i; + /* two nops for trampoline attach */ + EMIT(PPC_RAW_NOP()); + EMIT(PPC_RAW_NOP()); + #ifdef PPC64_ELF_ABI_v2 PPC_BPF_LL(_R2, _R13, offsetof(struct paca_struct, kernel_toc)); #else @@ -93,7 +98,7 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx) EMIT(PPC_RAW_NOP()); } -#define BPF_TAILCALL_PROLOGUE_SIZE 12 +#define BPF_TAILCALL_PROLOGUE_SIZE 20 if (bpf_has_stack_frame(ctx)) { /* @@ -1133,3 +1138,615 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * return 0; } + +#ifdef PPC64_ELF_ABI_v2 + +static __always_inline int bpf_check_and_patch(u32 *ip, ppc_inst_t old_inst, ppc_inst_t new_inst) +{ + ppc_inst_t org_inst = ppc_inst_read(ip); + if (!ppc_inst_equal(org_inst, old_inst)) { + pr_info("bpf_check_and_patch: ip: 0x%lx, org_inst(0x%x) != old_inst (0x%x)\n", + (unsigned long)ip, ppc_inst_val(org_inst), ppc_inst_val(old_inst)); + return -EBUSY; + } + if (ppc_inst_equal(org_inst, new_inst)) + return 1; + return patch_instruction(ip, new_inst); +} + +static u32 *bpf_find_existing_stub(u32 *ip, enum bpf_text_poke_type t, void *old_addr) +{ + int branch_flags = t == BPF_MOD_JUMP ? 0 : BRANCH_SET_LINK; + u32 *stub_addr = 0, *stub1, *stub2; + ppc_inst_t org_inst, old_inst; + + if (!old_addr) + return 0; + + stub1 = ip - (BPF_TRAMP_STUB_SIZE / sizeof(u32)) - (t == BPF_MOD_CALL ? 1 : 0); + stub2 = stub1 - (BPF_TRAMP_STUB_SIZE / sizeof(u32)); + org_inst = ppc_inst_read(ip); + if (!create_branch(_inst, ip, (unsigned long)stub1, branch_flags) && + ppc_inst_equal(org_inst, old_inst)) +
[RFC PATCH 2/3] powerpc/ftrace: Override ftrace_location_lookup() for MPROFILE_KERNEL
With CONFIG_MPROFILE_KERNEL, ftrace location is within the first 5 instructions of a function. Override ftrace_location_lookup() to search within this range for the ftrace location. Also convert kprobe_lookup_name() to utilize this function. Signed-off-by: Naveen N. Rao --- arch/powerpc/kernel/kprobes.c | 8 +--- arch/powerpc/kernel/trace/ftrace.c | 11 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 9a492fdec1dfbe..03cb50e4c8c3e8 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -50,13 +50,7 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); if (addr && !offset) { #ifdef CONFIG_KPROBES_ON_FTRACE - unsigned long faddr; - /* -* Per livepatch.h, ftrace location is always within the first -* 16 bytes of a function on powerpc with -mprofile-kernel. -*/ - faddr = ftrace_location_range((unsigned long)addr, - (unsigned long)addr + 16); + unsigned long faddr = ftrace_location_lookup((unsigned long)addr); if (faddr) addr = (kprobe_opcode_t *)faddr; else diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c index b65ca87a2eacb1..5127eb65c299af 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -1137,3 +1137,14 @@ char *arch_ftrace_match_adjust(char *str, const char *search) return str; } #endif /* PPC64_ELF_ABI_v1 */ + +#ifdef CONFIG_MPROFILE_KERNEL +unsigned long ftrace_location_lookup(unsigned long ip) +{ + /* +* Per livepatch.h, ftrace location is always within the first +* 16 bytes of a function on powerpc with -mprofile-kernel. +*/ + return ftrace_location_range(ip, ip + 16); +} +#endif -- 2.34.1
[RFC PATCH 1/3] ftrace: Add ftrace_location_lookup() to lookup address of ftrace location
Add a new function ftrace_location_lookup() that can be used to determine the exact ftrace location around function entry. This is useful on architectures where the ftrace location is not the very first instruction in a function. Such architectures can override this function to search for ftrace location and to return the exact address of the same. Convert some uses of ftrace_location() in BPF infrastructure to the new function. Signed-off-by: Naveen N. Rao --- include/linux/ftrace.h | 5 + kernel/bpf/trampoline.c | 27 +-- kernel/trace/ftrace.c | 14 ++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 708e9d610f1337..59791f2aa0b356 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -582,6 +582,7 @@ int ftrace_test_record(struct dyn_ftrace *rec, bool enable); void ftrace_run_stop_machine(int command); unsigned long ftrace_location(unsigned long ip); unsigned long ftrace_location_range(unsigned long start, unsigned long end); +unsigned long ftrace_location_lookup(unsigned long ip); unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec); unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec); @@ -795,6 +796,10 @@ static inline unsigned long ftrace_location(unsigned long ip) { return 0; } +static inline unsigned long ftrace_location_lookup(unsigned long ip) +{ + return 0; +} /* * Again users of functions that have ftrace_ops may not diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 4b6974a195c138..5da9d332cd0e10 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -117,25 +117,14 @@ static void bpf_trampoline_module_put(struct bpf_trampoline *tr) tr->mod = NULL; } -static int is_ftrace_location(void *ip) -{ - long addr; - - addr = ftrace_location((long)ip); - if (!addr) - return 0; - if (WARN_ON_ONCE(addr != (long)ip)) - return -EFAULT; - return 1; -} - static int unregister_fentry(struct bpf_trampoline *tr, void *old_addr) { void *ip = tr->func.addr; int ret; if (tr->func.ftrace_managed) - ret = unregister_ftrace_direct((long)ip, (long)old_addr); + ret = unregister_ftrace_direct(ftrace_location_lookup((unsigned long)ip), + (long)old_addr); else ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, old_addr, NULL); @@ -150,7 +139,8 @@ static int modify_fentry(struct bpf_trampoline *tr, void *old_addr, void *new_ad int ret; if (tr->func.ftrace_managed) - ret = modify_ftrace_direct((long)ip, (long)old_addr, (long)new_addr); + ret = modify_ftrace_direct(ftrace_location_lookup((unsigned long)ip), + (long)old_addr, (long)new_addr); else ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, old_addr, new_addr); return ret; @@ -162,10 +152,11 @@ static int register_fentry(struct bpf_trampoline *tr, void *new_addr) void *ip = tr->func.addr; int ret; - ret = is_ftrace_location(ip); - if (ret < 0) - return ret; - tr->func.ftrace_managed = ret; + ip = (void *)ftrace_location_lookup((unsigned long)ip); + tr->func.ftrace_managed = !!ip; + + if (!ip) + ip = tr->func.addr; if (bpf_trampoline_module_get(tr)) return -ENOENT; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index ff57a842fbebcd..6a68b86b2b6ac6 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1581,6 +1581,20 @@ unsigned long ftrace_location(unsigned long ip) return ftrace_location_range(ip, ip); } +/** + * ftrace_location_lookup - return exact address of traced location + * @ip: the instruction pointer to check + * + * Used to lookup traced location around function entry. This is + * especially useful on architectures where the traced location is + * not the very first instruction in a function. Such architectures + * should provide an implementation of this function. + */ +unsigned long __weak ftrace_location_lookup(unsigned long ip) +{ + return ftrace_location_range(ip, ip); +} + /** * ftrace_text_reserved - return true if range contains an ftrace location * @start: start of range to search -- 2.34.1
[RFC PATCH 0/3] powerpc64/bpf: Add support for BPF Trampolines
This is an early RFC series that adds support for BPF Trampolines on powerpc64. Some of the selftests are passing for me, but this needs more testing and I've likely missed a few things as well. A review of the patches and feedback about the overall approach will be great. This series depends on some of the other BPF JIT fixes and enhancements posted previously, as well as on ftrace direct enablement on powerpc which has also been posted in the past. - Naveen Naveen N. Rao (3): ftrace: Add ftrace_location_lookup() to lookup address of ftrace location powerpc/ftrace: Override ftrace_location_lookup() for MPROFILE_KERNEL powerpc64/bpf: Add support for bpf trampolines arch/powerpc/kernel/kprobes.c | 8 +- arch/powerpc/kernel/trace/ftrace.c | 11 + arch/powerpc/net/bpf_jit.h | 8 + arch/powerpc/net/bpf_jit_comp.c| 5 +- arch/powerpc/net/bpf_jit_comp64.c | 619 - include/linux/ftrace.h | 5 + kernel/bpf/trampoline.c| 27 +- kernel/trace/ftrace.c | 14 + 8 files changed, 670 insertions(+), 27 deletions(-) base-commit: 33ecb3e590194051dc57eee1125c1d372b14c946 -- 2.34.1
[RESEND PATCH v4] powerpc: Set crashkernel offset to mid of RMA region
On large config LPARs (having 192 and more cores), Linux fails to boot due to insufficient memory in the first memblock. It is due to the memory reservation for the crash kernel which starts at 128MB offset of the first memblock. This memory reservation for the crash kernel doesn't leave enough space in the first memblock to accommodate other essential system resources. The crash kernel start address was set to 128MB offset by default to ensure that the crash kernel get some memory below the RMA region which is used to be of size 256MB. But given that the RMA region size can be 512MB or more, setting the crash kernel offset to mid of RMA size will leave enough space for the kernel to allocate memory for other system resources. Since the above crash kernel offset change is only applicable to the LPAR platform, the LPAR feature detection is pushed before the crash kernel reservation. The rest of LPAR specific initialization will still be done during pseries_probe_fw_features as usual. This patch is dependent on changes to paca allocation for boot CPU. It expect boot CPU to discover 1T segment support which is introduced by the patch posted here: https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/239175.html Signed-off-by: Sourabh Jain Reported-by: Abdul haleem --- arch/powerpc/kernel/rtas.c | 6 ++ arch/powerpc/kexec/core.c | 15 +++ 2 files changed, 17 insertions(+), 4 deletions(-) --- Resend: add version number to the subject. Chnages in v4: - fix build issue for 32-bit. Changes in v3: https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/239371.html --- diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index 733e6ef36758..1f42aabbbab3 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -1313,6 +1313,12 @@ int __init early_init_dt_scan_rtas(unsigned long node, entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL); sizep = of_get_flat_dt_prop(node, "rtas-size", NULL); +#ifdef CONFIG_PPC64 + /* need this feature to decide the crashkernel offset */ + if (of_get_flat_dt_prop(node, "ibm,hypertas-functions", NULL)) + powerpc_firmware_features |= FW_FEATURE_LPAR; +#endif + if (basep && entryp && sizep) { rtas.base = *basep; rtas.entry = *entryp; diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index 8b68d9f91a03..abf5897ae88c 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -134,11 +134,18 @@ void __init reserve_crashkernel(void) if (!crashk_res.start) { #ifdef CONFIG_PPC64 /* -* On 64bit we split the RMO in half but cap it at half of -* a small SLB (128MB) since the crash kernel needs to place -* itself and some stacks to be in the first segment. +* On the LPAR platform place the crash kernel to mid of +* RMA size (512MB or more) to ensure the crash kernel +* gets enough space to place itself and some stack to be +* in the first segment. At the same time normal kernel +* also get enough space to allocate memory for essential +* system resource in the first segment. Keep the crash +* kernel starts at 128MB offset on other platforms. */ - crashk_res.start = min(0x800ULL, (ppc64_rma_size / 2)); + if (firmware_has_feature(FW_FEATURE_LPAR)) + crashk_res.start = ppc64_rma_size / 2; + else + crashk_res.start = min(0x800ULL, (ppc64_rma_size / 2)); #else crashk_res.start = KDUMP_KERNELBASE; #endif -- 2.34.1
Re: [PATCH v2 3/3] vstatus: Display an informational message when the VSTATUS character is pressed or TIOCSTAT ioctl is called.
On 06. 02. 22, 16:48, Walt Drummond wrote: When triggered by pressing the VSTATUS key or calling the TIOCSTAT ioctl, the n_tty line discipline will display a message on the user's tty that provides basic information about the system and an 'interesting' process in the current foreground process group, eg: load: 0.58 cmd: sleep 744474 [sleeping] 0.36r 0.00u 0.00s 0% 772k The status message provides: - System load average - Command name and process id (from the perspective of the session) - Scheduler state - Total wall-clock run time - User space run time - System space run time - Percentage of on-cpu time - Resident set size The message is only displayed when the tty has the VSTATUS character set, the local flags ICANON and IEXTEN are enabled and NOKERNINFO is disabled; it is always displayed when TIOCSTAT is called regardless of tty settings. Signed-off-by: Walt Drummond --- It looks like my comments were addressed. However you did not document the chances since v1 here. IOW, [v2] tag missing here. And please add the CCs I added last time, so that relevant people still can comment. thanks, -- js suse labs
Re: [PATCH v2 5/5] powerpc: Select ARCH_WANTS_MODULES_DATA_IN_VMALLOC on book3s/32 and 8xx
Christophe Leroy writes: > Le 03/02/2022 à 06:39, Michael Ellerman a écrit : >> Luis Chamberlain writes: >>> On Thu, Jan 27, 2022 at 11:28:12AM +, Christophe Leroy wrote: book3s/32 and 8xx have a separate area for allocating modules, defined by MODULES_VADDR / MODULES_END. On book3s/32, it is not possible to protect against execution on a page basis. A full 256M segment is either Exec or NoExec. The module area is in an Exec segment while vmalloc area is in a NoExec segment. In order to protect module data against execution, select ARCH_WANTS_MODULES_DATA_IN_VMALLOC. For the 8xx (and possibly other 32 bits platform in the future), there is no such constraint on Exec/NoExec protection, however there is a critical distance between kernel functions and callers that needs to remain below 32Mbytes in order to avoid costly trampolines. By allocating data outside of module area, we increase the chance for module text to remain within acceptable distance from kernel core text. So select ARCH_WANTS_MODULES_DATA_IN_VMALLOC for 8xx as well. Signed-off-by: Christophe Leroy Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras >>> >>> Cc list first and then the SOB. >> >> Just delete the Cc: list, it's meaningless. >> > > Was an easy way to copy you automatically with 'git send-email', but > getting it through linuxppc-dev list is enough I guess ? It's useful for making the tooling Cc the right people, it's fine to use them for that. But there's no value in committing them to the git history, I actively strip them when applying. The fact that someone is Cc'ed on a patch tells you nothing, given the volume of mail maintainers receive. The link tag back to the original submission gives you the Cc list anyway. cheers
[PATCH] Styleguide fix: Removed un-needed whitespaces and formatting errors in drivers/tty
There were lot of styleguide errors raised by checkpatch.pl against drivers/tty/* which I have fixed. There is zero code change apart from changes related to styleguide. checkpatch.pl returns 0 error for style guide now. --- drivers/tty/amiserial.c| 285 ++--- drivers/tty/ehv_bytechan.c | 5 +- drivers/tty/goldfish.c | 2 + 3 files changed, 142 insertions(+), 150 deletions(-) diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c index 1e60dbef6..15917254e 100644 --- a/drivers/tty/amiserial.c +++ b/drivers/tty/amiserial.c @@ -12,13 +12,13 @@ * (non hardware specific) changes to serial.c. * * The port is registered with the tty driver as minor device 64, and - * therefore other ports should should only use 65 upwards. + * therefore other ports should only use 65 upwards. * * Richard Lucock 28/12/99 * * Copyright (C) 1991, 1992 Linus Torvalds - * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, - * 1998, 1999 Theodore Ts'o + * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, + * 1998, 1999 Theodore Ts'o * */ @@ -78,8 +78,8 @@ struct serial_state { int ignore_status_mask; int timeout; int quot; - int IER;/* Interrupt Enable Register */ - int MCR;/* Modem control register */ + int IER;/* Interrupt Enable Register */ + int MCR;/* Modem control register */ int x_char; /* xon/xoff character */ }; @@ -116,9 +116,9 @@ static struct serial_state serial_state; #define SER_CTS (1<<4) #define SER_DSR (1<<3) -static __inline__ void rtsdtr_ctrl(int bits) +static inline void rtsdtr_ctrl(int bits) { -ciab.pra = ((bits & (SER_RTS | SER_DTR)) ^ (SER_RTS | SER_DTR)) | (ciab.pra & ~(SER_RTS | SER_DTR)); + ciab.pra = ((bits & (SER_RTS | SER_DTR)) ^ (SER_RTS | SER_DTR)) | (ciab.pra & ~(SER_RTS | SER_DTR)); } /* @@ -175,7 +175,7 @@ static void rs_start(struct tty_struct *tty) static void receive_chars(struct serial_state *info) { -int status; + int status; int serdatr; unsigned char ch, flag; struct async_icount *icount; @@ -189,10 +189,10 @@ static void receive_chars(struct serial_state *info) amiga_custom.intreq = IF_RBF; mb(); - if((serdatr & 0x1ff) == 0) - status |= UART_LSR_BI; - if(serdatr & SDR_OVRUN) - status |= UART_LSR_OE; + if ((serdatr & 0x1ff) == 0) + status |= UART_LSR_BI; + if (serdatr & SDR_OVRUN) + status |= UART_LSR_OE; ch = serdatr & 0xff; icount->rx++; @@ -213,45 +213,44 @@ static void receive_chars(struct serial_state *info) /* * For statistics only */ - if (status & UART_LSR_BI) { - status &= ~(UART_LSR_FE | UART_LSR_PE); - icount->brk++; - } else if (status & UART_LSR_PE) - icount->parity++; - else if (status & UART_LSR_FE) - icount->frame++; - if (status & UART_LSR_OE) - icount->overrun++; + if (status & UART_LSR_BI) { + status &= ~(UART_LSR_FE | UART_LSR_PE); + icount->brk++; + } else if (status & UART_LSR_PE) + icount->parity++; + else if (status & UART_LSR_FE) + icount->frame++; + if (status & UART_LSR_OE) + icount->overrun++; /* * Now check to see if character should be * ignored, and mask off conditions which * should be ignored. */ - if (status & info->ignore_status_mask) - goto out; + if (status & info->ignore_status_mask) + goto out; - status &= info->read_status_mask; - - if (status & (UART_LSR_BI)) { + status &= info->read_status_mask; + if (status & (UART_LSR_BI)) { #ifdef SERIAL_DEBUG_INTR - printk("handling break"); + printk("handling break"); #endif - flag = TTY_BREAK; - if (info->tport.flags & ASYNC_SAK) - do_SAK(info->tport.tty); - } else if (status & UART_LSR_PE) - flag = TTY_PARITY; - else if (status & UART_LSR_FE) - flag = TTY_FRAME; - if (status & UART_LSR_OE) { - /* -* Overrun is special, since it's -* reported immediately, and doesn't -* affect the current character -*/ -oe = 1; - } + flag = TTY_BREAK; + if (info->tport.flags & ASYNC_SAK) + do_SAK(info->tport.tty); +
[PATCH v2] i2c: pasemi: Drop I2C classes from platform driver variant
Drop I2C device-probing classes from platform variant of the PASemi controller as it is only used on platforms where I2C devices should be instantiated in devicetree. (The I2C_CLASS_DEPRECATED flag is not raised as up to this point no devices relied on the old behavior.) Fixes: d88ae2932df0 ("i2c: pasemi: Add Apple platform driver") Signed-off-by: Martin Povišer --- I am sending v2 as some people got their copy in v1 encrypted with their WKD keys (by accident). I changed email provider since. drivers/i2c/busses/i2c-pasemi-core.c | 1 - drivers/i2c/busses/i2c-pasemi-pci.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 4e161a4089d8..7728c8460dc0 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -333,7 +333,6 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) smbus->adapter.owner = THIS_MODULE; snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), "PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); - smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; smbus->adapter.algo = _algorithm; smbus->adapter.algo_data = smbus; diff --git a/drivers/i2c/busses/i2c-pasemi-pci.c b/drivers/i2c/busses/i2c-pasemi-pci.c index 1ab1f28744fb..cfc89e04eb94 100644 --- a/drivers/i2c/busses/i2c-pasemi-pci.c +++ b/drivers/i2c/busses/i2c-pasemi-pci.c @@ -56,6 +56,7 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, if (!smbus->ioaddr) return -EBUSY; + smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; error = pasemi_i2c_common_probe(smbus); if (error) return error; -- 2.33.0
Re: [PATCH] Styleguide fix: Removed un-needed whitespaces and formatting errors in drivers/tty
On Mon, Feb 07, 2022 at 12:33:07AM +0530, Ankit Kumar Pandey wrote: > There were lot of styleguide errors raised by checkpatch.pl against > drivers/tty/* which I have fixed. There is zero code change apart from > changes related to styleguide. checkpatch.pl returns 0 error for > style guide now. > > --- > drivers/tty/amiserial.c| 285 ++--- > drivers/tty/ehv_bytechan.c | 5 +- > drivers/tty/goldfish.c | 2 + > 3 files changed, 142 insertions(+), 150 deletions(-) > > diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c > index 1e60dbef6..15917254e 100644 > --- a/drivers/tty/amiserial.c > +++ b/drivers/tty/amiserial.c > @@ -12,13 +12,13 @@ > * (non hardware specific) changes to serial.c. > * > * The port is registered with the tty driver as minor device 64, and > - * therefore other ports should should only use 65 upwards. > + * therefore other ports should only use 65 upwards. > * > * Richard Lucock 28/12/99 > * > * Copyright (C) 1991, 1992 Linus Torvalds > - * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, > - * 1998, 1999 Theodore Ts'o > + * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, > + * 1998, 1999 Theodore Ts'o > * > */ > > @@ -78,8 +78,8 @@ struct serial_state { > int ignore_status_mask; > int timeout; > int quot; > - int IER;/* Interrupt Enable Register */ > - int MCR;/* Modem control register */ > + int IER;/* Interrupt Enable Register */ > + int MCR;/* Modem control register */ > int x_char; /* xon/xoff character */ > }; > > @@ -116,9 +116,9 @@ static struct serial_state serial_state; > #define SER_CTS (1<<4) > #define SER_DSR (1<<3) > > -static __inline__ void rtsdtr_ctrl(int bits) > +static inline void rtsdtr_ctrl(int bits) > { > -ciab.pra = ((bits & (SER_RTS | SER_DTR)) ^ (SER_RTS | SER_DTR)) | > (ciab.pra & ~(SER_RTS | SER_DTR)); > + ciab.pra = ((bits & (SER_RTS | SER_DTR)) ^ (SER_RTS | SER_DTR)) | > (ciab.pra & ~(SER_RTS | SER_DTR)); > } > > /* > @@ -175,7 +175,7 @@ static void rs_start(struct tty_struct *tty) > > static void receive_chars(struct serial_state *info) > { > -int status; > + int status; > int serdatr; > unsigned char ch, flag; > struct async_icount *icount; > @@ -189,10 +189,10 @@ static void receive_chars(struct serial_state *info) > amiga_custom.intreq = IF_RBF; > mb(); > > - if((serdatr & 0x1ff) == 0) > - status |= UART_LSR_BI; > - if(serdatr & SDR_OVRUN) > - status |= UART_LSR_OE; > + if ((serdatr & 0x1ff) == 0) > + status |= UART_LSR_BI; > + if (serdatr & SDR_OVRUN) > + status |= UART_LSR_OE; > > ch = serdatr & 0xff; > icount->rx++; > @@ -213,45 +213,44 @@ static void receive_chars(struct serial_state *info) > /* > * For statistics only > */ > - if (status & UART_LSR_BI) { > - status &= ~(UART_LSR_FE | UART_LSR_PE); > - icount->brk++; > - } else if (status & UART_LSR_PE) > - icount->parity++; > - else if (status & UART_LSR_FE) > - icount->frame++; > - if (status & UART_LSR_OE) > - icount->overrun++; > + if (status & UART_LSR_BI) { > + status &= ~(UART_LSR_FE | UART_LSR_PE); > + icount->brk++; > + } else if (status & UART_LSR_PE) > + icount->parity++; > + else if (status & UART_LSR_FE) > + icount->frame++; > + if (status & UART_LSR_OE) > + icount->overrun++; > > /* > * Now check to see if character should be > * ignored, and mask off conditions which > * should be ignored. > */ > - if (status & info->ignore_status_mask) > - goto out; > + if (status & info->ignore_status_mask) > + goto out; > > - status &= info->read_status_mask; > - > - if (status & (UART_LSR_BI)) { > + status &= info->read_status_mask; > + if (status & (UART_LSR_BI)) { > #ifdef SERIAL_DEBUG_INTR > - printk("handling break"); > + printk("handling break"); > #endif > - flag = TTY_BREAK; > - if (info->tport.flags & ASYNC_SAK) > - do_SAK(info->tport.tty); > - } else if (status & UART_LSR_PE) > - flag = TTY_PARITY; > - else if (status & UART_LSR_FE) > - flag = TTY_FRAME; > - if (status & UART_LSR_OE) { > - /* > - * Overrun is special, since it's > - * reported immediately, and doesn't > - * affect the current character > - */ > - oe
Re: [PATCH v2 3/3] vstatus: Display an informational message when the VSTATUS character is pressed or TIOCSTAT ioctl is called.
On Sun, Feb 06, 2022 at 07:48:54AM -0800, Walt Drummond wrote: > When triggered by pressing the VSTATUS key or calling the TIOCSTAT > ioctl, the n_tty line discipline will display a message on the user's > tty that provides basic information about the system and an > 'interesting' process in the current foreground process group, eg: > > load: 0.58 cmd: sleep 744474 [sleeping] 0.36r 0.00u 0.00s 0% 772k > > The status message provides: > - System load average > - Command name and process id (from the perspective of the session) > - Scheduler state > - Total wall-clock run time > - User space run time > - System space run time > - Percentage of on-cpu time > - Resident set size This should be documented somewhere, and not buried in a changelog text like this. Can you also add this information somewhere in the Documentation/ directory so that people have a hint as to what is going on here? > The message is only displayed when the tty has the VSTATUS character > set, the local flags ICANON and IEXTEN are enabled and NOKERNINFO is > disabled; it is always displayed when TIOCSTAT is called regardless of > tty settings. > > Signed-off-by: Walt Drummond > --- > drivers/tty/Makefile | 2 +- > drivers/tty/n_tty.c| 34 +++ > drivers/tty/n_tty_status.c | 181 + > drivers/tty/tty_io.c | 2 +- > include/linux/tty.h| 5 + > 5 files changed, 222 insertions(+), 2 deletions(-) > create mode 100644 drivers/tty/n_tty_status.c Also, any chance for a test to be added so that we can ensure that this doesn't change over time in ways that confuse/break people? Is this now a new user/kernel api format that we must preserve for forever? Can we add/remove items over time that make sense or are programs (not just people), going to parse this? > > diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile > index a2bd75fbaaa4..3539d7ab77e5 100644 > --- a/drivers/tty/Makefile > +++ b/drivers/tty/Makefile > @@ -2,7 +2,7 @@ > obj-$(CONFIG_TTY)+= tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \ > tty_buffer.o tty_port.o tty_mutex.o \ > tty_ldsem.o tty_baudrate.o tty_jobctrl.o \ > -n_null.o > +n_null.o n_tty_status.o > obj-$(CONFIG_LEGACY_PTYS)+= pty.o > obj-$(CONFIG_UNIX98_PTYS)+= pty.o > obj-$(CONFIG_AUDIT) += tty_audit.o > diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c > index 64a058a4c63b..fd70efc333d7 100644 > --- a/drivers/tty/n_tty.c > +++ b/drivers/tty/n_tty.c > @@ -80,6 +80,7 @@ > #define ECHO_BLOCK 256 > #define ECHO_DISCARD_WATERMARK N_TTY_BUF_SIZE - (ECHO_BLOCK + 32) > > +#define STATUS_LINE_LEN 160 /* tty status line will truncate at this > length */ Tabs please. > > #undef N_TTY_TRACE > #ifdef N_TTY_TRACE > @@ -127,6 +128,8 @@ struct n_tty_data { > struct mutex output_lock; > }; > > +static void n_tty_status(struct tty_struct *tty); > + > #define MASK(x) ((x) & (N_TTY_BUF_SIZE - 1)) > > static inline size_t read_cnt(struct n_tty_data *ldata) > @@ -1334,6 +1337,11 @@ static void n_tty_receive_char_special(struct > tty_struct *tty, unsigned char c) > commit_echoes(tty); > return; > } > + if (c == STATUS_CHAR(tty) && L_IEXTEN(tty)) { > + if (!L_NOKERNINFO(tty)) > + n_tty_status(tty); > + return; > + } > if (c == '\n') { > if (L_ECHO(tty) || L_ECHONL(tty)) { > echo_char_raw('\n', ldata); > @@ -1763,6 +1771,7 @@ static void n_tty_set_termios(struct tty_struct *tty, > struct ktermios *old) > set_bit(EOF_CHAR(tty), ldata->char_map); > set_bit('\n', ldata->char_map); > set_bit(EOL_CHAR(tty), ldata->char_map); > + set_bit(STATUS_CHAR(tty), ldata->char_map); > if (L_IEXTEN(tty)) { > set_bit(WERASE_CHAR(tty), ldata->char_map); > set_bit(LNEXT_CHAR(tty), ldata->char_map); > @@ -2413,6 +2422,26 @@ static unsigned long inq_canon(struct n_tty_data > *ldata) > return nr; > } > > +static void n_tty_status(struct tty_struct *tty) > +{ > + struct n_tty_data *ldata = tty->disc_data; > + char *msg; > + size_t len; > + > + msg = kzalloc(STATUS_LINE_LEN, GFP_KERNEL); Please check for memory failures. > + > + if (ldata->column != 0) { > + *msg = '\n'; > + len = n_tty_get_status(tty, msg + 1, STATUS_LINE_LEN - 1); > + } else { > + len = n_tty_get_status(tty, msg, STATUS_LINE_LEN); > + } > + > + do_n_tty_write(tty, NULL, msg, len); > + > + kfree(msg); > +} > + > static int
Re: [PATCH v2 2/3] status: Add user space API definitions for VSTATUS, NOKERNINFO and TIOCSTAT
On Sun, Feb 06, 2022 at 07:48:53AM -0800, Walt Drummond wrote: > Add definitions for the VSTATUS control character, and the NOKERNINFO > local control flag in the termios struct, and add an ioctl number for > the ioctl TIOCSTAT. Also add a default VSTATUS character (Ctrl-T) > default valuses in termios.c_cc. Do this for all architectures. > > Signed-off-by: Walt Drummond > --- > arch/alpha/include/asm/termios.h | 4 ++-- > arch/alpha/include/uapi/asm/ioctls.h | 1 + > arch/alpha/include/uapi/asm/termbits.h | 2 ++ > arch/ia64/include/asm/termios.h | 4 ++-- > arch/ia64/include/uapi/asm/termbits.h| 2 ++ > arch/mips/include/asm/termios.h | 4 ++-- > arch/mips/include/uapi/asm/ioctls.h | 1 + > arch/mips/include/uapi/asm/termbits.h| 2 ++ > arch/parisc/include/asm/termios.h| 4 ++-- > arch/parisc/include/uapi/asm/ioctls.h| 1 + > arch/parisc/include/uapi/asm/termbits.h | 2 ++ > arch/powerpc/include/asm/termios.h | 4 ++-- > arch/powerpc/include/uapi/asm/ioctls.h | 2 ++ > arch/powerpc/include/uapi/asm/termbits.h | 2 ++ > arch/s390/include/asm/termios.h | 4 ++-- > arch/sh/include/uapi/asm/ioctls.h| 1 + > arch/sparc/include/uapi/asm/ioctls.h | 1 + > arch/sparc/include/uapi/asm/termbits.h | 2 ++ > arch/xtensa/include/uapi/asm/ioctls.h| 1 + > include/asm-generic/termios.h| 4 ++-- > include/uapi/asm-generic/ioctls.h| 1 + > include/uapi/asm-generic/termbits.h | 2 ++ > 22 files changed, 37 insertions(+), 14 deletions(-) > > diff --git a/arch/alpha/include/asm/termios.h > b/arch/alpha/include/asm/termios.h > index b7c77bb1bfd2..d28ddc649286 100644 > --- a/arch/alpha/include/asm/termios.h > +++ b/arch/alpha/include/asm/termios.h > @@ -8,9 +8,9 @@ > werase=^W kill=^U reprint=^R sxtc=\0 > intr=^C quit=^\ susp=^Z > start=^Qstop=^S lnext=^Vdiscard=^U > - vmin=\1 vtime=\0 > + vmin=\1 vtime=\0status=^T > */ > -#define INIT_C_CC > "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000" > +#define INIT_C_CC > "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000\024" > > /* > * Translate a "termio" structure into a "termios". Ugh. > diff --git a/arch/alpha/include/uapi/asm/ioctls.h > b/arch/alpha/include/uapi/asm/ioctls.h > index 971311605288..70fdeab2b5f2 100644 > --- a/arch/alpha/include/uapi/asm/ioctls.h > +++ b/arch/alpha/include/uapi/asm/ioctls.h > @@ -124,5 +124,6 @@ > > #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ > #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ > +#define TIOCSTAT _IO('T', 0x5E) /* display process group stats on tty */ > > #endif /* _ASM_ALPHA_IOCTLS_H */ > diff --git a/arch/alpha/include/uapi/asm/termbits.h > b/arch/alpha/include/uapi/asm/termbits.h > index 4575ba34a0ea..9a1b9aa92d29 100644 > --- a/arch/alpha/include/uapi/asm/termbits.h > +++ b/arch/alpha/include/uapi/asm/termbits.h > @@ -70,6 +70,7 @@ struct ktermios { > #define VDISCARD 15 > #define VMIN 16 > #define VTIME 17 > +#define VSTATUS 18 > > /* c_iflag bits */ > #define IGNBRK 001 > @@ -203,6 +204,7 @@ struct ktermios { > #define PENDIN 0x2000 > #define IEXTEN 0x0400 > #define EXTPROC 0x1000 > +#define NOKERNINFO 0x4000 Here, and elsewhere, you seem to mix tabs and spaces. Please use what is in the original file (tabs here.) > /* Values for the ACTION argument to `tcflow'. */ > #define TCOOFF 0 > diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h > index 589c026444cc..40e83f9b6ead 100644 > --- a/arch/ia64/include/asm/termios.h > +++ b/arch/ia64/include/asm/termios.h > @@ -15,9 +15,9 @@ > eof=^D vtime=\0vmin=\1 sxtc=\0 > start=^Qstop=^S susp=^Z eol=\0 > reprint=^R discard=^U werase=^W lnext=^V > - eol2=\0 > + eol2=\0 status=^T Same here. And for the other files in this patch. Let's keep them unified please. thanks, greg k-h
[PATCH v2 3/3] vstatus: Display an informational message when the VSTATUS character is pressed or TIOCSTAT ioctl is called.
When triggered by pressing the VSTATUS key or calling the TIOCSTAT ioctl, the n_tty line discipline will display a message on the user's tty that provides basic information about the system and an 'interesting' process in the current foreground process group, eg: load: 0.58 cmd: sleep 744474 [sleeping] 0.36r 0.00u 0.00s 0% 772k The status message provides: - System load average - Command name and process id (from the perspective of the session) - Scheduler state - Total wall-clock run time - User space run time - System space run time - Percentage of on-cpu time - Resident set size The message is only displayed when the tty has the VSTATUS character set, the local flags ICANON and IEXTEN are enabled and NOKERNINFO is disabled; it is always displayed when TIOCSTAT is called regardless of tty settings. Signed-off-by: Walt Drummond --- drivers/tty/Makefile | 2 +- drivers/tty/n_tty.c| 34 +++ drivers/tty/n_tty_status.c | 181 + drivers/tty/tty_io.c | 2 +- include/linux/tty.h| 5 + 5 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 drivers/tty/n_tty_status.c diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile index a2bd75fbaaa4..3539d7ab77e5 100644 --- a/drivers/tty/Makefile +++ b/drivers/tty/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_TTY) += tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \ tty_buffer.o tty_port.o tty_mutex.o \ tty_ldsem.o tty_baudrate.o tty_jobctrl.o \ - n_null.o + n_null.o n_tty_status.o obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o obj-$(CONFIG_AUDIT)+= tty_audit.o diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 64a058a4c63b..fd70efc333d7 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -80,6 +80,7 @@ #define ECHO_BLOCK 256 #define ECHO_DISCARD_WATERMARK N_TTY_BUF_SIZE - (ECHO_BLOCK + 32) +#define STATUS_LINE_LEN 160 /* tty status line will truncate at this length */ #undef N_TTY_TRACE #ifdef N_TTY_TRACE @@ -127,6 +128,8 @@ struct n_tty_data { struct mutex output_lock; }; +static void n_tty_status(struct tty_struct *tty); + #define MASK(x) ((x) & (N_TTY_BUF_SIZE - 1)) static inline size_t read_cnt(struct n_tty_data *ldata) @@ -1334,6 +1337,11 @@ static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c) commit_echoes(tty); return; } + if (c == STATUS_CHAR(tty) && L_IEXTEN(tty)) { + if (!L_NOKERNINFO(tty)) + n_tty_status(tty); + return; + } if (c == '\n') { if (L_ECHO(tty) || L_ECHONL(tty)) { echo_char_raw('\n', ldata); @@ -1763,6 +1771,7 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) set_bit(EOF_CHAR(tty), ldata->char_map); set_bit('\n', ldata->char_map); set_bit(EOL_CHAR(tty), ldata->char_map); + set_bit(STATUS_CHAR(tty), ldata->char_map); if (L_IEXTEN(tty)) { set_bit(WERASE_CHAR(tty), ldata->char_map); set_bit(LNEXT_CHAR(tty), ldata->char_map); @@ -2413,6 +2422,26 @@ static unsigned long inq_canon(struct n_tty_data *ldata) return nr; } +static void n_tty_status(struct tty_struct *tty) +{ + struct n_tty_data *ldata = tty->disc_data; + char *msg; + size_t len; + + msg = kzalloc(STATUS_LINE_LEN, GFP_KERNEL); + + if (ldata->column != 0) { + *msg = '\n'; + len = n_tty_get_status(tty, msg + 1, STATUS_LINE_LEN - 1); + } else { + len = n_tty_get_status(tty, msg, STATUS_LINE_LEN); + } + + do_n_tty_write(tty, NULL, msg, len); + + kfree(msg); +} + static int n_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { @@ -2430,6 +2459,11 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file, retval = read_cnt(ldata); up_write(>termios_rwsem); return put_user(retval, (unsigned int __user *) arg); + case TIOCSTAT: + down_read(>termios_rwsem); + n_tty_status(tty); + up_read(>termios_rwsem); + return 0; default: return n_tty_ioctl_helper(tty, file, cmd, arg); } diff --git a/drivers/tty/n_tty_status.c b/drivers/tty/n_tty_status.c new file mode 100644 index ..f0e053651368 --- /dev/null +++ b/drivers/tty/n_tty_status.c @@ -0,0 +1,181 @@ +//
[PATCH v2 2/3] status: Add user space API definitions for VSTATUS, NOKERNINFO and TIOCSTAT
Add definitions for the VSTATUS control character, and the NOKERNINFO local control flag in the termios struct, and add an ioctl number for the ioctl TIOCSTAT. Also add a default VSTATUS character (Ctrl-T) default valuses in termios.c_cc. Do this for all architectures. Signed-off-by: Walt Drummond --- arch/alpha/include/asm/termios.h | 4 ++-- arch/alpha/include/uapi/asm/ioctls.h | 1 + arch/alpha/include/uapi/asm/termbits.h | 2 ++ arch/ia64/include/asm/termios.h | 4 ++-- arch/ia64/include/uapi/asm/termbits.h| 2 ++ arch/mips/include/asm/termios.h | 4 ++-- arch/mips/include/uapi/asm/ioctls.h | 1 + arch/mips/include/uapi/asm/termbits.h| 2 ++ arch/parisc/include/asm/termios.h| 4 ++-- arch/parisc/include/uapi/asm/ioctls.h| 1 + arch/parisc/include/uapi/asm/termbits.h | 2 ++ arch/powerpc/include/asm/termios.h | 4 ++-- arch/powerpc/include/uapi/asm/ioctls.h | 2 ++ arch/powerpc/include/uapi/asm/termbits.h | 2 ++ arch/s390/include/asm/termios.h | 4 ++-- arch/sh/include/uapi/asm/ioctls.h| 1 + arch/sparc/include/uapi/asm/ioctls.h | 1 + arch/sparc/include/uapi/asm/termbits.h | 2 ++ arch/xtensa/include/uapi/asm/ioctls.h| 1 + include/asm-generic/termios.h| 4 ++-- include/uapi/asm-generic/ioctls.h| 1 + include/uapi/asm-generic/termbits.h | 2 ++ 22 files changed, 37 insertions(+), 14 deletions(-) diff --git a/arch/alpha/include/asm/termios.h b/arch/alpha/include/asm/termios.h index b7c77bb1bfd2..d28ddc649286 100644 --- a/arch/alpha/include/asm/termios.h +++ b/arch/alpha/include/asm/termios.h @@ -8,9 +8,9 @@ werase=^W kill=^U reprint=^R sxtc=\0 intr=^C quit=^\ susp=^Z start=^Qstop=^S lnext=^Vdiscard=^U - vmin=\1 vtime=\0 + vmin=\1 vtime=\0status=^T */ -#define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000" +#define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000\024" /* * Translate a "termio" structure into a "termios". Ugh. diff --git a/arch/alpha/include/uapi/asm/ioctls.h b/arch/alpha/include/uapi/asm/ioctls.h index 971311605288..70fdeab2b5f2 100644 --- a/arch/alpha/include/uapi/asm/ioctls.h +++ b/arch/alpha/include/uapi/asm/ioctls.h @@ -124,5 +124,6 @@ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT0x545D /* read serial port inline interrupt counts */ +#define TIOCSTAT _IO('T', 0x5E) /* display process group stats on tty */ #endif /* _ASM_ALPHA_IOCTLS_H */ diff --git a/arch/alpha/include/uapi/asm/termbits.h b/arch/alpha/include/uapi/asm/termbits.h index 4575ba34a0ea..9a1b9aa92d29 100644 --- a/arch/alpha/include/uapi/asm/termbits.h +++ b/arch/alpha/include/uapi/asm/termbits.h @@ -70,6 +70,7 @@ struct ktermios { #define VDISCARD 15 #define VMIN 16 #define VTIME 17 +#define VSTATUS 18 /* c_iflag bits */ #define IGNBRK 001 @@ -203,6 +204,7 @@ struct ktermios { #define PENDIN 0x2000 #define IEXTEN 0x0400 #define EXTPROC0x1000 +#define NOKERNINFO 0x4000 /* Values for the ACTION argument to `tcflow'. */ #defineTCOOFF 0 diff --git a/arch/ia64/include/asm/termios.h b/arch/ia64/include/asm/termios.h index 589c026444cc..40e83f9b6ead 100644 --- a/arch/ia64/include/asm/termios.h +++ b/arch/ia64/include/asm/termios.h @@ -15,9 +15,9 @@ eof=^D vtime=\0vmin=\1 sxtc=\0 start=^Qstop=^S susp=^Z eol=\0 reprint=^R discard=^U werase=^W lnext=^V - eol2=\0 + eol2=\0 status=^T */ -#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" +#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0\024" /* * Translate a "termio" structure into a "termios". Ugh. diff --git a/arch/ia64/include/uapi/asm/termbits.h b/arch/ia64/include/uapi/asm/termbits.h index 000a1a297c75..0b5fea00343b 100644 --- a/arch/ia64/include/uapi/asm/termbits.h +++ b/arch/ia64/include/uapi/asm/termbits.h @@ -67,6 +67,7 @@ struct ktermios { #define VWERASE 14 #define VLNEXT 15 #define VEOL2 16 +#define VSTATUS 17 /* c_iflag bits */ #define IGNBRK 001 @@ -189,6 +190,7 @@ struct ktermios { #define PENDIN 004 #define IEXTEN 010 #define EXTPROC020 +#define NOKERNINFO 040 /* tcflow() and TCXONC use these */ #defineTCOOFF 0 diff --git a/arch/mips/include/asm/termios.h b/arch/mips/include/asm/termios.h index bc29eeacc55a..04729018d882 100644 --- a/arch/mips/include/asm/termios.h +++ b/arch/mips/include/asm/termios.h @@ -17,9 +17,9 @@ * vmin=\1 vtime=\0eol2=\0 swtc=\0 * start=^Qstop=^S susp=^Z vdsusp= * reprint=^R discard=^U
[PATCH v2 1/3] vstatus: Allow the n_tty line dicipline to write to a user tty
Refactor the implementation of n_tty_write() into do_n_tty_write(), and change n_tty_write() to call do_n_tty_write() after acquiring tty.termios_rwsem. This allows the n_tty line dicipline to write to a user tty via do_n_tty_write() when already holding tty.termios_rwsem. Signed-off-by: Walt Drummond --- drivers/tty/n_tty.c | 69 +++-- include/linux/tty.h | 2 +- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 0ec93f1a61f5..64a058a4c63b 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -2231,45 +2231,24 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, return retval; } -/** - * n_tty_write - write function for tty - * @tty: tty device - * @file: file object - * @buf: userspace buffer pointer - * @nr: size of I/O - * - * Write function of the terminal device. This is serialized with - * respect to other write callers but not to termios changes, reads - * and other such events. Since the receive code will echo characters, - * thus calling driver write methods, the output_lock is used in - * the output processing functions called here as well as in the - * echo processing function to protect the column state and space - * left in the buffer. - * - * This code must be sure never to sleep through a hangup. - * - * Locking: output_lock to protect column state and space left - * (note that the process_output*() functions take this - * lock themselves) - */ - -static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, - const unsigned char *buf, size_t nr) +static ssize_t do_n_tty_write(struct tty_struct *tty, struct file *file, + const unsigned char *buf, size_t nr) { const unsigned char *b = buf; DEFINE_WAIT_FUNC(wait, woken_wake_function); int c; ssize_t retval = 0; + lockdep_assert_held_read(>termios_rwsem); + /* Job control check -- must be done at start (POSIX.1 7.1.1.4). */ - if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { + if (L_TOSTOP(tty) && + !(file && file->f_op->write_iter != redirected_tty_write)) { retval = tty_check_change(tty); if (retval) return retval; } - down_read(>termios_rwsem); - /* Write out any echoed characters that are still pending */ process_echoes(tty); @@ -2336,10 +2315,44 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, remove_wait_queue(>write_wait, ); if (nr && tty->fasync) set_bit(TTY_DO_WRITE_WAKEUP, >flags); - up_read(>termios_rwsem); + return (b - buf) ? b - buf : retval; } +/** + * n_tty_write - write function for tty + * @tty: tty device + * @file: file object + * @buf: userspace buffer pointer + * @nr: size of I/O + * + * Write function of the terminal device. This is serialized with + * respect to other write callers but not to termios changes, reads + * and other such events. Since the receive code will echo characters, + * thus calling driver write methods, the output_lock is used in + * the output processing functions called here as well as in the + * echo processing function to protect the column state and space + * left in the buffer. + * + * This code must be sure never to sleep through a hangup. + * + * Locking: output_lock to protect column state and space left + * (note that the process_output*() functions take this + * lock themselves) + */ + +static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, + const unsigned char *buf, size_t nr) +{ + ssize_t retval = 0; + + down_read(>termios_rwsem); + retval = do_n_tty_write(tty, file, buf, nr); + up_read(>termios_rwsem); + + return retval; +} + /** * n_tty_poll - poll method for N_TTY * @tty: terminal device diff --git a/include/linux/tty.h b/include/linux/tty.h index 168e57e40bbb..cbe5d535a69d 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -237,7 +237,7 @@ struct tty_file_private { static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file) { - return file->f_flags & O_NONBLOCK || + return (file && file->f_flags & O_NONBLOCK) || test_bit(TTY_LDISC_CHANGING, >flags); } -- 2.30.2
[PATCH v2 0/3] vstatus: TTY status message request
This patchset adds TTY status message request feature to the n_tty line dicipline. This feature prints a brief message containing basic system and process group information to a user's TTY in response to a new control character in the line dicipline (default Ctrl-T) or the TIOCSTAT ioctl. The message contains the current system load, the name and PID of an interesting process in the forground process group, it's run time, percent CPU usage and RSS. An example of this message is: load: 0.31 cmd: sleep 3616843 [sleeping] 0.36r 0.00u 0.00s 0% 696k This feature is in many other Unix systems, both current and historical. In other implementations, this feature would also send SIGINFO to the process group; this implementation does not. User API visible changes are limited to: - The addition of VSTATUS in termios.c_cc[] - The addition of NOKERNINFO bit in termios.l_cflags - The addition of the TIOCSTAT ioctl number None of these changes break the existing kernel api as the termios structure on all architectures has enough space in the control character array (.c_cc) for the new character. Walt Drummond (3): vstatus: Allow the n_tty line dicipline to write to a user tty status: Add user space API definitions for VSTATUS, NOKERNINFO and TIOCSTAT vstatus: Display an informational message when the VSTATUS character is pressed or TIOCSTAT ioctl is called. arch/alpha/include/asm/termios.h | 4 +- arch/alpha/include/uapi/asm/ioctls.h | 1 + arch/alpha/include/uapi/asm/termbits.h | 2 + arch/ia64/include/asm/termios.h | 4 +- arch/ia64/include/uapi/asm/termbits.h| 2 + arch/mips/include/asm/termios.h | 4 +- arch/mips/include/uapi/asm/ioctls.h | 1 + arch/mips/include/uapi/asm/termbits.h| 2 + arch/parisc/include/asm/termios.h| 4 +- arch/parisc/include/uapi/asm/ioctls.h| 1 + arch/parisc/include/uapi/asm/termbits.h | 2 + arch/powerpc/include/asm/termios.h | 4 +- arch/powerpc/include/uapi/asm/ioctls.h | 2 + arch/powerpc/include/uapi/asm/termbits.h | 2 + arch/s390/include/asm/termios.h | 4 +- arch/sh/include/uapi/asm/ioctls.h| 1 + arch/sparc/include/uapi/asm/ioctls.h | 1 + arch/sparc/include/uapi/asm/termbits.h | 2 + arch/xtensa/include/uapi/asm/ioctls.h| 1 + drivers/tty/Makefile | 2 +- drivers/tty/n_tty.c | 103 + drivers/tty/n_tty_status.c | 181 +++ drivers/tty/tty_io.c | 2 +- include/asm-generic/termios.h| 4 +- include/linux/tty.h | 7 +- include/uapi/asm-generic/ioctls.h| 1 + include/uapi/asm-generic/termbits.h | 2 + 27 files changed, 301 insertions(+), 45 deletions(-) create mode 100644 drivers/tty/n_tty_status.c -- 2.30.2
Re: [PATCH v2] i2c: pasemi: Drop I2C classes from platform driver variant
On 04/02/2022 18.59, Martin Povišer wrote: > Drop I2C device-probing classes from platform variant of the PASemi > controller as it is only used on platforms where I2C devices should > be instantiated in devicetree. (The I2C_CLASS_DEPRECATED flag is not > raised as up to this point no devices relied on the old behavior.) > > Fixes: d88ae2932df0 ("i2c: pasemi: Add Apple platform driver") > Signed-off-by: Martin Povišer Acked-by: Hector Martin Heh, so that's where this was... I remember running into this and wondering if there was a way to turn it off. -- Hector Martin (mar...@marcan.st) Public Key: https://mrcn.st/pub