lkml.org 
[lkml]   [2018]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 04/12] __wr_after_init: x86_64: __wr_op
On Wed, Dec 19, 2018 at 11:33:30PM +0200, Igor Stoppa wrote:
> +void *__wr_op(unsigned long dst, unsigned long src, __kernel_size_t len,
> + enum wr_op_type op)
> +{
> + temporary_mm_state_t prev;
> + unsigned long offset;
> + unsigned long wr_poking_addr;
> +
> + /* Confirm that the writable mapping exists. */
> + if (WARN_ONCE(!wr_ready, "No writable mapping available"))
> + return (void *)dst;
> +
> + if (WARN_ONCE(op >= WR_OPS_NUMBER, "Invalid WR operation.") ||
> + WARN_ONCE(!is_wr_after_init(dst, len), "Invalid WR range."))
> + return (void *)dst;
> +
> + offset = dst - (unsigned long)&__start_wr_after_init;
> + wr_poking_addr = wr_poking_base + offset;
> + local_irq_disable();
> + prev = use_temporary_mm(wr_poking_mm);
> +
> + if (op == WR_MEMCPY)
> + copy_to_user((void __user *)wr_poking_addr, (void *)src, len);
> + else if (op == WR_MEMSET)
> + memset_user((void __user *)wr_poking_addr, (u8)src, len);
> +
> + unuse_temporary_mm(prev);
> + local_irq_enable();
> + return (void *)dst;
> +}

I think you're causing yourself more headaches by implementing this "op"
function. Here's some generic code:

void *wr_memcpy(void *dst, void *src, unsigned int len)
{
wr_state_t wr_state;
void *wr_poking_addr = __wr_addr(dst);

local_irq_disable();
wr_enable(&wr_state);
__wr_memcpy(wr_poking_addr, src, len);
wr_disable(&wr_state);
local_irq_enable();

return dst;
}

Now, x86 can define appropriate macros and functions to use the temporary_mm
functionality, and other architectures can do what makes sense to them.

\
 
 \ /
  Last update: 2018-12-20 19:50    [W:0.129 / U:3.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site